Mercurial > libervia-backend
annotate frontends/src/wix/main_window.py @ 502:debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
- MUC rooms are special entities
- Primitivus: special entities are shown at the top of the contacts list above a divider,
presence updates are temporary ignored for them
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 25 Sep 2012 23:10:22 +0200 |
parents | e9634d2e7b38 |
children | 886754295efe |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 wix: a SAT frontend | |
459 | 6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
0 | 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 | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
16 GNU Affero General Public License for more details. |
0 | 17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
0 | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | |
21 | |
22 | |
227 | 23 from sat_frontends.quick_frontend.quick_chat_list import QuickChatList |
24 from sat_frontends.quick_frontend.quick_app import QuickApp | |
25 from sat_frontends.quick_frontend.quick_contact_management import QuickContactManagement | |
0 | 26 import wx |
227 | 27 from sat_frontends.wix.contact_list import ContactList |
28 from sat_frontends.wix.chat import Chat | |
29 from sat_frontends.wix.param import Param | |
30 from sat_frontends.wix.xmlui import XMLUI | |
31 from sat_frontends.wix.gateways import GatewaysManager | |
32 from sat_frontends.wix.profile import Profile | |
33 from sat_frontends.wix.profile_manager import ProfileManager | |
0 | 34 import gobject |
35 import os.path | |
36 import pdb | |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
37 from sat.tools.jid import JID |
72 | 38 from logging import debug, info, warning, error |
227 | 39 import sat_frontends.wix.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,\ |
191 | 44 idABOUT,\ |
51
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,\ |
191 | 50 idFIND_GATEWAYS = range(10) |
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): | |
366
0806a65a5fa9
wix: updated paths to use media_dir
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
65 QuickApp.__init__(self) |
68 | 66 wx.Frame.__init__(self,None, title="SàT Wix", size=(300,500)) |
0 | 67 |
68 | 68 #sizer |
69 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
70 self.SetSizer(self.sizer) | |
71 | |
0 | 72 #Frame elements |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
73 self.contact_list = ContactList(self, self) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
74 self.contact_list.registerActivatedCB(self.onContactActivated) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
75 self.contact_list.Hide() |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
76 self.sizer.Add(self.contact_list, 1, flag=wx.EXPAND) |
68 | 77 |
0 | 78 self.chat_wins=ChatList(self) |
79 self.CreateStatusBar() | |
80 | |
81 #ToolBar | |
82 self.tools=self.CreateToolBar() | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
83 self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=[status[1] for status in const_STATUS], |
0 | 84 style=wx.CB_DROPDOWN | wx.CB_READONLY) |
85 self.tools.AddControl(self.statusBox) | |
86 self.tools.AddSeparator() | |
87 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER) | |
88 self.tools.AddControl(self.statusTxt) | |
89 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox) | |
90 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt) | |
91 self.tools.Disable() | |
366
0806a65a5fa9
wix: updated paths to use media_dir
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
92 |
0806a65a5fa9
wix: updated paths to use media_dir
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
93 |
11 | 94 |
95 #tray icon | |
366
0806a65a5fa9
wix: updated paths to use media_dir
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
96 ticon = wx.Icon(os.path.join(self.media_dir, 'icons/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) | |
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() |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
122 self.contact_list.Show() |
68 | 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() |
191 | 135 connectMenu.Append(idABOUT,_("A&bout"),_(" About %s") % APP_NAME) |
70 | 136 connectMenu.Append(idEXIT,_("E&xit"),_(" Terminate the program")) |
0 | 137 contactMenu = wx.Menu() |
70 | 138 contactMenu.Append(idADD_CONTACT, _("&Add contact"),_(" Add a contact to your list")) |
139 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
|
140 contactMenu.AppendSeparator() |
70 | 141 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
|
142 communicationMenu = wx.Menu() |
72 | 143 communicationMenu.Append(idJOIN_ROOM, _("&Join Room"),_(" Join a Multi-User Chat room")) |
70 | 144 communicationMenu.Append(idFIND_GATEWAYS, _("&Find Gateways"),_(" Find gateways to legacy IM")) |
68 | 145 self.menuBar = wx.MenuBar() |
70 | 146 self.menuBar.Append(connectMenu,_("&General")) |
147 self.menuBar.Append(contactMenu,_("&Contacts")) | |
148 self.menuBar.Append(communicationMenu,_("&Communication")) | |
68 | 149 self.SetMenuBar(self.menuBar) |
0 | 150 |
101 | 151 #additionals menus |
152 #FIXME: do this in a more generic way (in quickapp) | |
153 add_menus = self.bridge.getMenus() | |
154 for menu in add_menus: | |
155 category,item,type = menu | |
156 assert(type=="NORMAL") #TODO: manage other types | |
157 menu_idx = self.menuBar.FindMenu(category) | |
158 current_menu = None | |
159 if menu_idx == wx.NOT_FOUND: | |
160 #the menu is new, we create it | |
161 current_menu = wx.Menu() | |
162 self.menuBar.Append(current_menu, category) | |
163 else: | |
164 current_menu = self.menuBar.GetMenu(menu_idx) | |
165 assert(current_menu != None) | |
166 item_id = wx.NewId() | |
167 help_string = self.bridge.getMenuHelp(category, item, type) | |
168 current_menu.Append(item_id, item, help = help_string) | |
169 #now we register the event | |
170 def event_answer(e): | |
219
782319a64ac6
primitivus, wix: added forgotten profile
Goffi <goffi@goffi.org>
parents:
204
diff
changeset
|
171 id = self.bridge.callMenu(category, item, type, self.profile) |
101 | 172 self.current_action_ids.add(id) |
173 wx.EVT_MENU(self, item_id, event_answer) | |
174 | |
175 | |
0 | 176 #events |
177 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest) | |
1 | 178 wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest) |
0 | 179 wx.EVT_MENU(self, idPARAM, self.onParam) |
191 | 180 wx.EVT_MENU(self, idABOUT, self.onAbout) |
0 | 181 wx.EVT_MENU(self, idEXIT, self.onExit) |
182 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact) | |
183 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
|
184 wx.EVT_MENU(self, idSHOW_PROFILE, self.onShowProfile) |
72 | 185 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
|
186 wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways) |
0 | 187 |
188 | |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
189 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
|
190 QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile) |
0 | 191 |
192 def showAlert(self, message): | |
193 # TODO: place this in a separate class | |
194 popup=wx.PopupWindow(self) | |
195 ### following code come from wxpython demo | |
196 popup.SetBackgroundColour("CADET BLUE") | |
197 st = wx.StaticText(popup, -1, message, pos=(10,10)) | |
198 sz = st.GetBestSize() | |
199 popup.SetSize( (sz.width+20, sz.height+20) ) | |
200 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2 | |
201 popup.SetPosition((x,0)) | |
202 popup.Show() | |
203 wx.CallLater(5000,popup.Destroy) | |
204 | |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
205 def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None): |
0 | 206 if type == 'info': |
207 flags = wx.OK | wx.ICON_INFORMATION | |
208 elif type == 'error': | |
209 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
|
210 elif type == 'yes/no': |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
211 flags = wx.YES_NO | wx.ICON_QUESTION |
0 | 212 else: |
213 flags = wx.OK | wx.ICON_INFORMATION | |
70 | 214 error(_('unmanaged dialog type: %s'), type) |
0 | 215 dlg = wx.MessageDialog(self, message, title, flags) |
216 answer = dlg.ShowModal() | |
217 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
|
218 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
|
219 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
|
220 answer_cb(True if (answer == wx.ID_YES or answer == wx.ID_OK) else False, *data) |
0 | 221 |
222 def setStatusOnline(self, online=True): | |
223 """enable/disable controls, must be called when local user online status change""" | |
224 if online: | |
225 self.SetStatusText(msgONLINE) | |
226 self.tools.Enable() | |
227 else: | |
228 self.SetStatusText(msgOFFLINE) | |
229 self.tools.Disable() | |
230 return | |
231 | |
232 def askConfirmation(self, type, id, data): | |
233 #TODO: refactor this in QuickApp | |
70 | 234 debug (_("Confirmation asked")) |
0 | 235 answer_data={} |
391 | 236 if type == "FILE_TRANSFER": |
237 debug (_("File transfer confirmation asked")) | |
70 | 238 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"]}, |
239 _('File Request'), | |
0 | 240 wx.YES_NO | wx.ICON_QUESTION |
241 ) | |
242 answer=dlg.ShowModal() | |
243 if answer==wx.ID_YES: | |
70 | 244 filename = wx.FileSelector(_("Where do you want to save the file ?"), flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) |
0 | 245 if filename: |
246 answer_data["dest_path"] = filename | |
247 self.bridge.confirmationAnswer(id, True, answer_data) | |
70 | 248 self.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename)) |
0 | 249 else: |
250 answer = wx.ID_NO | |
251 if answer==wx.ID_NO: | |
252 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
|
253 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
254 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
|
255 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
256 elif type == "YES/NO": |
70 | 257 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
|
258 dlg = wx.MessageDialog(self, data["message"], |
70 | 259 _('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
|
260 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
|
261 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
262 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
|
263 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
|
264 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
|
265 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
|
266 self.bridge.confirmationAnswer(id, False, {}) |
0 | 267 |
268 dlg.Destroy() | |
269 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
270 def actionResult(self, type, id, data): |
70 | 271 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
|
272 if not id in self.current_action_ids: |
70 | 273 debug (_('unknown id, ignoring')) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 elif type == "SUCCESS": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
278 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
|
279 dlg = wx.MessageDialog(self, data["message"], |
70 | 280 _('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
|
281 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
|
282 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
283 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
|
284 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
|
285 elif type == "ERROR": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
286 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
|
287 dlg = wx.MessageDialog(self, data["message"], |
70 | 288 _('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
|
289 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
|
290 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
291 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
|
292 dlg.Destroy() |
103 | 293 elif type == "XMLUI": |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
294 self.current_action_ids.remove(id) |
103 | 295 debug (_("XML user interface received")) |
91 | 296 misc = {} |
297 #FIXME FIXME FIXME: must clean all this crap ! | |
298 title = _('Form') | |
299 if data['type'] == _('registration'): | |
103 | 300 title = _('Registration') |
91 | 301 misc['target'] = data['target'] |
302 misc['action_back'] = self.bridge.gatewayRegister | |
103 | 303 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
|
304 elif type == "RESULT": |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
305 self.current_action_ids.remove(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
306 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
|
307 callback = self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
308 del self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
309 callback(data) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
310 elif type == "DICT_DICT": |
28 | 311 self.current_action_ids.remove(id) |
312 if self.current_action_ids_cb.has_key(id): | |
313 callback = self.current_action_ids_cb[id] | |
314 del self.current_action_ids_cb[id] | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
315 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
|
316 else: |
70 | 317 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
|
318 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
|
319 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
320 |
0 | 321 |
322 def progressCB(self, id, title, message): | |
323 data = self.bridge.getProgress(id) | |
324 if data: | |
325 if not self.pbar: | |
326 #first answer, we must construct the bar | |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
120
diff
changeset
|
327 self.pbar = wx.ProgressDialog(title, message, float(data['size']), None, |
0 | 328 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
|
329 self.pbar.finish_value = float(data['size']) |
0 | 330 |
331 self.pbar.Update(int(data['position'])) | |
332 elif self.pbar: | |
333 self.pbar.Update(self.pbar.finish_value) | |
334 return | |
335 | |
336 wx.CallLater(10, self.progressCB, id, title, message) | |
337 | |
338 def waitProgress (self, id, title, message): | |
339 self.pbar = None | |
340 wx.CallLater(10, self.progressCB, id, title, message) | |
341 | |
342 | |
343 | |
344 ### events ### | |
345 | |
346 def onContactActivated(self, jid): | |
70 | 347 debug (_("onContactActivated: %s"), jid) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
348 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
|
349 self.chat_wins[jid.short].Hide() |
0 | 350 else: |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
351 self.chat_wins[jid.short].Show() |
0 | 352 |
353 def onConnectRequest(self, e): | |
68 | 354 self.bridge.connect(self.profile) |
0 | 355 |
1 | 356 def onDisconnectRequest(self, e): |
68 | 357 self.bridge.disconnect(self.profile) |
1 | 358 |
0 | 359 def __updateStatus(self): |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
360 show = filter(lambda x:x[1] == self.statusBox.GetValue(), const_STATUS)[0][0] |
0 | 361 status = self.statusTxt.GetValue() |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
362 self.bridge.setPresence(show=show, statuses={'default':status}, profile_key=self.profile) #FIXME: manage multilingual statuses |
0 | 363 |
364 def onStatusChange(self, e): | |
70 | 365 debug(_("Status change request")) |
0 | 366 self.__updateStatus() |
367 | |
368 def onParam(self, e): | |
70 | 369 debug(_("Param request")) |
105 | 370 #xmlui = self.bridge.getParamsUI(self.profile) |
371 #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
|
372 param=Param(self) |
0 | 373 |
191 | 374 def onAbout(self, e): |
375 about = wx.AboutDialogInfo() | |
376 about.SetName(APP_NAME) | |
377 about.SetVersion (unicode(self.bridge.getVersion())) | |
459 | 378 about.SetCopyright(u"(C) 2009, 2010, 2011, 2012 Jérôme Poisson aka Goffi") |
191 | 379 about.SetDescription( _(u"%(name)s is a SàT (Salut à Toi) frontend\n"+ |
380 u"%(name)s is based on WxPython, and is the standard graphic interface of SàT") % {'name':APP_NAME}) | |
381 about.SetWebSite(("http://www.goffi.org", "Goffi's non-hebdo (french)")) | |
382 about.SetDevelopers([ "Goffi (Jérôme Poisson)"]) | |
383 try: | |
384 with open(LICENCE_PATH,"r") as licence: | |
385 about.SetLicence(''.join(licence.readlines())) | |
386 except: | |
387 pass | |
388 | |
389 wx.AboutBox(about) | |
390 | |
0 | 391 def onExit(self, e): |
392 self.Close() | |
393 | |
394 def onAddContact(self, e): | |
70 | 395 debug(_("Add contact request")) |
0 | 396 dlg = wx.TextEntryDialog( |
70 | 397 self, _('Please enter new contact JID'), |
398 _('Adding a contact'), _('name@server.tld')) | |
0 | 399 |
400 if dlg.ShowModal() == wx.ID_OK: | |
401 jid=JID(dlg.GetValue()) | |
402 if jid.is_valid(): | |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
403 self.bridge.addContact(jid.short, profile_key=self.profile) |
0 | 404 else: |
70 | 405 error (_("'%s' is an invalid JID !"), jid) |
0 | 406 #TODO: notice the user |
407 | |
408 dlg.Destroy() | |
409 | |
410 def onRemoveContact(self, e): | |
70 | 411 debug(_("Remove contact request")) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
412 target = self.contact_list.getSelection() |
0 | 413 if not target: |
70 | 414 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
415 _('Error'), | |
0 | 416 wx.OK | wx.ICON_ERROR |
417 ) | |
418 dlg.ShowModal() | |
419 dlg.Destroy() | |
420 return | |
421 | |
70 | 422 dlg = wx.MessageDialog(self, _("Are you sure you want to delete %s from your roster list ?") % target.short, |
423 _('Contact suppression'), | |
0 | 424 wx.YES_NO | wx.ICON_QUESTION |
425 ) | |
426 | |
427 if dlg.ShowModal() == wx.ID_YES: | |
70 | 428 info(_("Unsubscribing %s presence"), target.short) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
429 self.bridge.delContact(target.short, profile_key=self.profile) |
0 | 430 |
431 dlg.Destroy() | |
432 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
433 def onShowProfile(self, e): |
70 | 434 debug(_("Show contact's profile request")) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
435 target = self.contact_list.getSelection() |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
436 if not target: |
70 | 437 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
438 _('Error'), | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
439 wx.OK | wx.ICON_ERROR |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
440 ) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
441 dlg.ShowModal() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
442 dlg.Destroy() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
443 return |
491
1e4731f1e1d7
wix: renamed id variable to avoid reserved name
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
444 _id = self.bridge.getCard(target.short, profile_key=self.profile) |
1e4731f1e1d7
wix: renamed id variable to avoid reserved name
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
445 self.current_action_ids.add(_id) |
1e4731f1e1d7
wix: renamed id variable to avoid reserved name
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
446 self.current_action_ids_cb[_id] = self.onProfileReceived |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
447 |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
448 def onProfileReceived(self, data): |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
449 """Called when a profile is received""" |
70 | 450 debug (_('Profile received: [%s]') % data) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
451 profile=Profile(self, data) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
452 |
72 | 453 def onJoinRoom(self, e): |
454 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
|
455 #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
|
456 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
|
457 self, _("Please enter MUC's JID"), |
204 | 458 #_('Entering a MUC room'), 'test@conference.necton2.int') |
459 _('Entering a MUC room'), 'room@muc_service.server.tld') | |
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
|
460 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
|
461 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
|
462 if room_jid.is_valid(): |
405
10b4f577d0c0
MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
463 self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile) |
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
|
464 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
|
465 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
|
466 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
467 def onFindGateways(self, e): |
70 | 468 debug(_("Find Gateways request")) |
491
1e4731f1e1d7
wix: renamed id variable to avoid reserved name
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
469 _id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain, self.profile) |
1e4731f1e1d7
wix: renamed id variable to avoid reserved name
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
470 self.current_action_ids.add(_id) |
1e4731f1e1d7
wix: renamed id variable to avoid reserved name
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
471 self.current_action_ids_cb[_id] = self.onGatewaysFound |
28 | 472 |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
473 def onGatewaysFound(self, data): |
28 | 474 """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
|
475 target = data['__private__']['target'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
476 del data['__private__'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
477 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
|
478 |
0 | 479 def onClose(self, e): |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
480 QuickApp.onExit(self) |
70 | 481 info(_("Exiting...")) |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
482 for win in self.chat_wins: |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
483 self.chat_wins[win].Destroy() |
0 | 484 e.Skip() |
11 | 485 |
486 def onTrayClick(self, e): | |
70 | 487 debug(_("Tray Click")) |
11 | 488 if self.IsShown(): |
489 self.Hide() | |
490 else: | |
491 self.Show() | |
492 self.Raise() | |
493 e.Skip() | |
0 | 494 |