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