annotate frontends/wix/main_window.py @ 52:6455fb62ff83

Connection/disconnection signals - wix, sortilege: management of this new signals /!\ sortilege is bugged, the contact list window is not updated correctly
author Goffi <goffi@goffi.org>
date Thu, 07 Jan 2010 01:55:30 +1100
parents 8c67ea98ab91
children 6dfe5bb10008
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 wix: a SAT frontend
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22
goffi@necton2
parents:
diff changeset
23 import wx
goffi@necton2
parents:
diff changeset
24 from chat import Chat
goffi@necton2
parents:
diff changeset
25 from param import Param
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents: 33
diff changeset
26 from form import Form
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents: 25
diff changeset
27 from gateways import GatewaysManager
42
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
28 from profile import Profile
0
goffi@necton2
parents:
diff changeset
29 import gobject
goffi@necton2
parents:
diff changeset
30 import os.path
goffi@necton2
parents:
diff changeset
31 import pdb
goffi@necton2
parents:
diff changeset
32 from tools.jid import JID
goffi@necton2
parents:
diff changeset
33 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
34 from quick_frontend.quick_chat_list import QuickChatList
goffi@necton2
parents:
diff changeset
35 from quick_frontend.quick_contact_list import QuickContactList
goffi@necton2
parents:
diff changeset
36 from quick_frontend.quick_app import QuickApp
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
37 from quick_frontend.quick_contact_management import QuickContactManagement
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
38 from cgi import escape
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
39 import sys
0
goffi@necton2
parents:
diff changeset
40
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
41 IMAGE_DIR = sys.path[0]+'/images'
0
goffi@necton2
parents:
diff changeset
42
goffi@necton2
parents:
diff changeset
43 msgOFFLINE = "offline"
goffi@necton2
parents:
diff changeset
44 msgONLINE = "online"
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
45 idCONNECT,\
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
46 idDISCONNECT,\
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
47 idEXIT,\
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
48 idPARAM,\
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
49 idADD_CONTACT,\
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
50 idREMOVE_CONTACT,\
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
51 idSHOW_PROFILE,\
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
52 idFIND_GATEWAYS = range(8)
0
goffi@necton2
parents:
diff changeset
53 const_DEFAULT_GROUP = "Unclassed"
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
54 const_STATUS = [("", "Online", None),
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
55 ("chat", "Free for chat", "green"),
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
56 ("away", "AFK", "brown"),
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
57 ("dnd", "DND", "red"),
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
58 ("xa", "Away", "red")]
0
goffi@necton2
parents:
diff changeset
59
goffi@necton2
parents:
diff changeset
60 class ChatList(QuickChatList):
goffi@necton2
parents:
diff changeset
61 """This class manage the list of chat windows"""
goffi@necton2
parents:
diff changeset
62
goffi@necton2
parents:
diff changeset
63 def __init__(self, host):
goffi@necton2
parents:
diff changeset
64 QuickChatList.__init__(self, host)
goffi@necton2
parents:
diff changeset
65
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
66 def createChat(self, target):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
67 return Chat(target, self.host)
0
goffi@necton2
parents:
diff changeset
68
goffi@necton2
parents:
diff changeset
69
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
70 class ContactList(wx.SimpleHtmlListBox, QuickContactList):
0
goffi@necton2
parents:
diff changeset
71 """Customized control to manage contacts."""
goffi@necton2
parents:
diff changeset
72
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
73 def __init__(self, parent, CM):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
74 wx.SimpleHtmlListBox.__init__(self, parent, -1)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
75 QuickContactList.__init__(self, CM)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
76 self.host = parent
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
77 self.Bind(wx.EVT_LISTBOX_DCLICK, self.onActivated)
0
goffi@necton2
parents:
diff changeset
78
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
79 def __find_idx(self, jid, reverse=False):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
80 """Find indexes of given jid in contact list
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
81 @return: list of indexes"""
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
82 result=[]
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
83 for i in range(self.GetCount()):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
84 if self.GetClientData(i).short == jid.short:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
85 result.append(i)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
86 return result
0
goffi@necton2
parents:
diff changeset
87
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
88 def replace(self, jid):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
89 debug("update %s" % jid)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
90 if not self.__find_idx(jid):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
91 self.add(jid)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
92 else:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
93 for i in self.__find_idx(jid):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
94 self.SetString(i, self.__presentItem(jid))
0
goffi@necton2
parents:
diff changeset
95
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
96 def disconnect(self, jid):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
97 self.remove(jid) #for now, we only show online contacts
0
goffi@necton2
parents:
diff changeset
98
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
99 def __presentItem(self, jid):
0
goffi@necton2
parents:
diff changeset
100 """Make a nice presentation of the contact in the list."""
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
101 name = self.CM.getAttr(jid,'name')
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
102 nick = self.CM.getAttr(jid,'nick')
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
103 show = filter(lambda x:x[0]==self.CM.getAttr(jid,'show'), const_STATUS)[0]
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
104 #show[0]==shortcut
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
105 #show[1]==human readable
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
106 #show[2]==color (or None)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
107 show_html = "<font color='%s'>[%s]</font>" % (show[2], show[1]) if show[2] else ""
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
108 status = self.CM.getAttr(jid,'status') or ''
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
109 avatar = self.CM.getAttr(jid,'avatar') or IMAGE_DIR+'/empty_avatar.png'
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
110
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
111 #XXX: yes table I know :) but wxHTML* doesn't support CSS
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
112 html = """
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
113 <table border='0'>
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
114 <td>
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
115 <img height='64' width='64' src='%s' />
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
116 </td>
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
117 <td>
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
118 <b>%s</b> %s<br />
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
119 <i>%s</i>
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
120 </td>
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
121 </table>
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
122 """ % (avatar,
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
123 escape(nick or name or jid.node or jid.short),
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
124 show_html,
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
125 escape(status))
0
goffi@necton2
parents:
diff changeset
126
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
127 return html
0
goffi@necton2
parents:
diff changeset
128
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
129 def clear_contacts(self):
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
130 """Clear all the contact list"""
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
131 self.Clear()
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
132
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
133 def add(self, jid):
0
goffi@necton2
parents:
diff changeset
134 """add a contact to the list"""
goffi@necton2
parents:
diff changeset
135 debug ("adding %s",jid)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
136 idx = self.Append(self.__presentItem(jid))
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
137
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
138 self.SetClientData(idx, jid)
0
goffi@necton2
parents:
diff changeset
139
goffi@necton2
parents:
diff changeset
140 def remove(self, jid):
goffi@necton2
parents:
diff changeset
141 """remove a contact from the list"""
goffi@necton2
parents:
diff changeset
142 debug ("removing %s",jid)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
143 list_idx = self.__find_idx(jid)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
144 list_idx.reverse() #we me make some deletions, we have to reverse the order
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
145 for i in list_idx:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
146 self.Delete(i)
0
goffi@necton2
parents:
diff changeset
147
goffi@necton2
parents:
diff changeset
148 def onActivated(self, event):
goffi@necton2
parents:
diff changeset
149 """Called when a contact is clicked or activated with keyboard."""
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
150 data = self.getSelection()
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
151 self.onActivatedCB(data)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
152 event.Skip()
0
goffi@necton2
parents:
diff changeset
153
goffi@necton2
parents:
diff changeset
154 def getSelection(self):
goffi@necton2
parents:
diff changeset
155 """Return the selected contact, or an empty string if there is not"""
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
156 if self.GetSelection() == wx.NOT_FOUND:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
157 return "" #FIXME: gof: à améliorer
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
158 data = self.GetClientData(self.GetSelection())
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
159 return data
0
goffi@necton2
parents:
diff changeset
160
goffi@necton2
parents:
diff changeset
161 def registerActivatedCB(self, cb):
goffi@necton2
parents:
diff changeset
162 """Register a callback with manage contact activation."""
goffi@necton2
parents:
diff changeset
163 self.onActivatedCB=cb
goffi@necton2
parents:
diff changeset
164
goffi@necton2
parents:
diff changeset
165 class MainWindow(wx.Frame, QuickApp):
goffi@necton2
parents:
diff changeset
166 """main app window"""
goffi@necton2
parents:
diff changeset
167
goffi@necton2
parents:
diff changeset
168 def __init__(self):
goffi@necton2
parents:
diff changeset
169 wx.Frame.__init__(self,None, title="SAT Wix", size=(400,200))
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
170 self.CM = QuickContactManagement() #gof:
0
goffi@necton2
parents:
diff changeset
171
goffi@necton2
parents:
diff changeset
172
goffi@necton2
parents:
diff changeset
173 #Frame elements
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
174 self.contactList = ContactList(self, self.CM)
0
goffi@necton2
parents:
diff changeset
175 self.contactList.registerActivatedCB(self.onContactActivated)
goffi@necton2
parents:
diff changeset
176 self.chat_wins=ChatList(self)
goffi@necton2
parents:
diff changeset
177 self.CreateStatusBar()
goffi@necton2
parents:
diff changeset
178 self.createMenus()
goffi@necton2
parents:
diff changeset
179
goffi@necton2
parents:
diff changeset
180 #ToolBar
goffi@necton2
parents:
diff changeset
181 self.tools=self.CreateToolBar()
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
182 self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=[status[1] for status in const_STATUS],
0
goffi@necton2
parents:
diff changeset
183 style=wx.CB_DROPDOWN | wx.CB_READONLY)
goffi@necton2
parents:
diff changeset
184 self.tools.AddControl(self.statusBox)
goffi@necton2
parents:
diff changeset
185 self.tools.AddSeparator()
goffi@necton2
parents:
diff changeset
186 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER)
goffi@necton2
parents:
diff changeset
187 self.tools.AddControl(self.statusTxt)
goffi@necton2
parents:
diff changeset
188 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox)
goffi@necton2
parents:
diff changeset
189 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt)
goffi@necton2
parents:
diff changeset
190 self.tools.Disable()
11
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
191
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
192 #tray icon
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
193 ticon = wx.Icon(IMAGE_DIR+'/crystal/tray_icon.xpm', wx.BITMAP_TYPE_XPM)
11
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
194 self.tray_icon = wx.TaskBarIcon()
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
195 self.tray_icon.SetIcon(ticon, "Wix jabber client")
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
196 wx.EVT_TASKBAR_LEFT_UP(self.tray_icon, self.onTrayClick)
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
197
0
goffi@necton2
parents:
diff changeset
198
goffi@necton2
parents:
diff changeset
199 #events
goffi@necton2
parents:
diff changeset
200 self.Bind(wx.EVT_CLOSE, self.onClose, self)
goffi@necton2
parents:
diff changeset
201
goffi@necton2
parents:
diff changeset
202 QuickApp.__init__(self)
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
203
0
goffi@necton2
parents:
diff changeset
204 self.Show()
goffi@necton2
parents:
diff changeset
205
goffi@necton2
parents:
diff changeset
206 def createMenus(self):
goffi@necton2
parents:
diff changeset
207 info("Creating menus")
goffi@necton2
parents:
diff changeset
208 connectMenu = wx.Menu()
goffi@necton2
parents:
diff changeset
209 connectMenu.Append(idCONNECT, "&Connect CTRL-c"," Connect to the server")
1
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
210 connectMenu.Append(idDISCONNECT, "&Disconnect CTRL-d"," Disconnect from the server")
0
goffi@necton2
parents:
diff changeset
211 connectMenu.Append(idPARAM,"&Parameters"," Configure the program")
goffi@necton2
parents:
diff changeset
212 connectMenu.AppendSeparator()
goffi@necton2
parents:
diff changeset
213 connectMenu.Append(idEXIT,"E&xit"," Terminate the program")
goffi@necton2
parents:
diff changeset
214 contactMenu = wx.Menu()
goffi@necton2
parents:
diff changeset
215 contactMenu.Append(idADD_CONTACT, "&Add contact"," Add a contact to your list")
goffi@necton2
parents:
diff changeset
216 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
217 contactMenu.AppendSeparator()
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
218 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
219 communicationMenu = wx.Menu()
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
220 communicationMenu.Append(idFIND_GATEWAYS, "&Find Gateways"," Find gateways to legacy IM")
0
goffi@necton2
parents:
diff changeset
221 menuBar = wx.MenuBar()
goffi@necton2
parents:
diff changeset
222 menuBar.Append(connectMenu,"&General")
goffi@necton2
parents:
diff changeset
223 menuBar.Append(contactMenu,"&Contacts")
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
224 menuBar.Append(communicationMenu,"&Communication")
0
goffi@necton2
parents:
diff changeset
225 self.SetMenuBar(menuBar)
goffi@necton2
parents:
diff changeset
226
goffi@necton2
parents:
diff changeset
227 #events
goffi@necton2
parents:
diff changeset
228 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest)
1
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
229 wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest)
0
goffi@necton2
parents:
diff changeset
230 wx.EVT_MENU(self, idPARAM, self.onParam)
goffi@necton2
parents:
diff changeset
231 wx.EVT_MENU(self, idEXIT, self.onExit)
goffi@necton2
parents:
diff changeset
232 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact)
goffi@necton2
parents:
diff changeset
233 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
234 wx.EVT_MENU(self, idSHOW_PROFILE, self.onShowProfile)
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
235 wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways)
0
goffi@necton2
parents:
diff changeset
236
goffi@necton2
parents:
diff changeset
237
goffi@necton2
parents:
diff changeset
238 def newMessage(self, from_jid, msg, type, to_jid):
goffi@necton2
parents:
diff changeset
239 QuickApp.newMessage(self, from_jid, msg, type, to_jid)
goffi@necton2
parents:
diff changeset
240
goffi@necton2
parents:
diff changeset
241 def showAlert(self, message):
goffi@necton2
parents:
diff changeset
242 # TODO: place this in a separate class
goffi@necton2
parents:
diff changeset
243 popup=wx.PopupWindow(self)
goffi@necton2
parents:
diff changeset
244 ### following code come from wxpython demo
goffi@necton2
parents:
diff changeset
245 popup.SetBackgroundColour("CADET BLUE")
goffi@necton2
parents:
diff changeset
246 st = wx.StaticText(popup, -1, message, pos=(10,10))
goffi@necton2
parents:
diff changeset
247 sz = st.GetBestSize()
goffi@necton2
parents:
diff changeset
248 popup.SetSize( (sz.width+20, sz.height+20) )
goffi@necton2
parents:
diff changeset
249 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2
goffi@necton2
parents:
diff changeset
250 popup.SetPosition((x,0))
goffi@necton2
parents:
diff changeset
251 popup.Show()
goffi@necton2
parents:
diff changeset
252 wx.CallLater(5000,popup.Destroy)
goffi@necton2
parents:
diff changeset
253
goffi@necton2
parents:
diff changeset
254 def showDialog(self, message, title="", type="info"):
goffi@necton2
parents:
diff changeset
255 if type == 'info':
goffi@necton2
parents:
diff changeset
256 flags = wx.OK | wx.ICON_INFORMATION
goffi@necton2
parents:
diff changeset
257 elif type == 'error':
goffi@necton2
parents:
diff changeset
258 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
259 elif type == 'yes/no':
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
260 flags = wx.YES_NO | wx.ICON_QUESTION
0
goffi@necton2
parents:
diff changeset
261 else:
goffi@necton2
parents:
diff changeset
262 flags = wx.OK | wx.ICON_INFORMATION
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
263 error('unmanaged dialog type: %s', type)
0
goffi@necton2
parents:
diff changeset
264 dlg = wx.MessageDialog(self, message, title, flags)
goffi@necton2
parents:
diff changeset
265 answer = dlg.ShowModal()
goffi@necton2
parents:
diff changeset
266 dlg.Destroy()
goffi@necton2
parents:
diff changeset
267 return True if (answer == wx.ID_YES or answer == wx.ID_OK) else False
goffi@necton2
parents:
diff changeset
268
goffi@necton2
parents:
diff changeset
269 def setStatusOnline(self, online=True):
goffi@necton2
parents:
diff changeset
270 """enable/disable controls, must be called when local user online status change"""
goffi@necton2
parents:
diff changeset
271 if online:
goffi@necton2
parents:
diff changeset
272 self.SetStatusText(msgONLINE)
goffi@necton2
parents:
diff changeset
273 self.tools.Enable()
goffi@necton2
parents:
diff changeset
274 else:
goffi@necton2
parents:
diff changeset
275 self.SetStatusText(msgOFFLINE)
goffi@necton2
parents:
diff changeset
276 self.tools.Disable()
goffi@necton2
parents:
diff changeset
277 return
goffi@necton2
parents:
diff changeset
278
goffi@necton2
parents:
diff changeset
279
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
280 def presenceUpdate(self, jabber_id, show, priority, statuses):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
281 QuickApp.presenceUpdate(self, jabber_id, show, priority, statuses)
0
goffi@necton2
parents:
diff changeset
282
goffi@necton2
parents:
diff changeset
283 def askConfirmation(self, type, id, data):
goffi@necton2
parents:
diff changeset
284 #TODO: refactor this in QuickApp
goffi@necton2
parents:
diff changeset
285 debug ("Confirmation asked")
goffi@necton2
parents:
diff changeset
286 answer_data={}
goffi@necton2
parents:
diff changeset
287 if type == "FILE_TRANSFERT":
goffi@necton2
parents:
diff changeset
288 debug ("File transfert confirmation asked")
goffi@necton2
parents:
diff changeset
289 dlg = wx.MessageDialog(self, "The contact %s wants to send you the file %s\nDo you accept ?" % (data["from"], data["filename"]),
goffi@necton2
parents:
diff changeset
290 'File Request',
goffi@necton2
parents:
diff changeset
291 wx.YES_NO | wx.ICON_QUESTION
goffi@necton2
parents:
diff changeset
292 )
goffi@necton2
parents:
diff changeset
293 answer=dlg.ShowModal()
goffi@necton2
parents:
diff changeset
294 if answer==wx.ID_YES:
goffi@necton2
parents:
diff changeset
295 filename = wx.FileSelector("Where do you want to save the file ?", flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
goffi@necton2
parents:
diff changeset
296 if filename:
goffi@necton2
parents:
diff changeset
297 answer_data["dest_path"] = filename
goffi@necton2
parents:
diff changeset
298 self.bridge.confirmationAnswer(id, True, answer_data)
goffi@necton2
parents:
diff changeset
299 self.waitProgress(id, "File Transfer", "Copying %s" % os.path.basename(filename))
goffi@necton2
parents:
diff changeset
300 else:
goffi@necton2
parents:
diff changeset
301 answer = wx.ID_NO
goffi@necton2
parents:
diff changeset
302 if answer==wx.ID_NO:
goffi@necton2
parents:
diff changeset
303 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
304
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
305 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
306
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
307 elif type == "YES/NO":
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
308 debug ("Yes/No confirmation asked")
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
309 dlg = wx.MessageDialog(self, data["message"],
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
310 'Confirmation',
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
311 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
312 )
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
313 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
314 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
315 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
316 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
317 self.bridge.confirmationAnswer(id, False, {})
0
goffi@necton2
parents:
diff changeset
318
goffi@necton2
parents:
diff changeset
319 dlg.Destroy()
goffi@necton2
parents:
diff changeset
320
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
321 def actionResult(self, type, id, data):
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
322 debug ("actionResult: type = [%s] id = [%s] data = [%s]" % (type, id, data))
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
323 if not id in self.current_action_ids:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
324 debug ('unknown id, ignoring')
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
325 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
326 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
327 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
328 elif type == "SUCCESS":
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
329 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
330 dlg = wx.MessageDialog(self, data["message"],
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
331 'Success',
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
332 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
333 )
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
334 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
335 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
336 elif type == "ERROR":
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
337 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
338 dlg = wx.MessageDialog(self, data["message"],
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
339 'Error',
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
340 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
341 )
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
342 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
343 dlg.Destroy()
33
b9bb5d8e0cc7 In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents: 28
diff changeset
344 elif type == "FORM":
b9bb5d8e0cc7 In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents: 28
diff changeset
345 self.current_action_ids.remove(id)
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents: 33
diff changeset
346 debug ("Form received")
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
347 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
348 elif type == "RESULT":
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
349 self.current_action_ids.remove(id)
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
350 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
351 callback = self.current_action_ids_cb[id]
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
352 del self.current_action_ids_cb[id]
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
353 callback(data)
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
354 elif type == "DICT_DICT":
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents: 25
diff changeset
355 self.current_action_ids.remove(id)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents: 25
diff changeset
356 if self.current_action_ids_cb.has_key(id):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents: 25
diff changeset
357 callback = self.current_action_ids_cb[id]
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents: 25
diff changeset
358 del self.current_action_ids_cb[id]
42
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
359 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
360 else:
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
361 error ("FIXME FIXME FIXME: type [%s] not implemented" % type)
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
362 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
363
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
364
0
goffi@necton2
parents:
diff changeset
365
goffi@necton2
parents:
diff changeset
366 def progressCB(self, id, title, message):
goffi@necton2
parents:
diff changeset
367 data = self.bridge.getProgress(id)
goffi@necton2
parents:
diff changeset
368 if data:
goffi@necton2
parents:
diff changeset
369 if not data['position']:
goffi@necton2
parents:
diff changeset
370 data['position'] = '0'
goffi@necton2
parents:
diff changeset
371 if not self.pbar:
goffi@necton2
parents:
diff changeset
372 #first answer, we must construct the bar
goffi@necton2
parents:
diff changeset
373 self.pbar = wx.ProgressDialog(title, message, int(data['size']), None,
goffi@necton2
parents:
diff changeset
374 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME)
goffi@necton2
parents:
diff changeset
375 self.pbar.finish_value = int(data['size'])
goffi@necton2
parents:
diff changeset
376
goffi@necton2
parents:
diff changeset
377 self.pbar.Update(int(data['position']))
goffi@necton2
parents:
diff changeset
378 elif self.pbar:
goffi@necton2
parents:
diff changeset
379 self.pbar.Update(self.pbar.finish_value)
goffi@necton2
parents:
diff changeset
380 return
goffi@necton2
parents:
diff changeset
381
goffi@necton2
parents:
diff changeset
382 wx.CallLater(10, self.progressCB, id, title, message)
goffi@necton2
parents:
diff changeset
383
goffi@necton2
parents:
diff changeset
384 def waitProgress (self, id, title, message):
goffi@necton2
parents:
diff changeset
385 self.pbar = None
goffi@necton2
parents:
diff changeset
386 wx.CallLater(10, self.progressCB, id, title, message)
goffi@necton2
parents:
diff changeset
387
goffi@necton2
parents:
diff changeset
388
goffi@necton2
parents:
diff changeset
389
goffi@necton2
parents:
diff changeset
390 ### events ###
goffi@necton2
parents:
diff changeset
391
goffi@necton2
parents:
diff changeset
392 def onContactActivated(self, jid):
goffi@necton2
parents:
diff changeset
393 debug ("onContactActivated: %s", jid)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
394 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
395 self.chat_wins[jid.short].Hide()
0
goffi@necton2
parents:
diff changeset
396 else:
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
397 self.chat_wins[jid.short].Show()
0
goffi@necton2
parents:
diff changeset
398
goffi@necton2
parents:
diff changeset
399 def onConnectRequest(self, e):
goffi@necton2
parents:
diff changeset
400 self.bridge.connect()
goffi@necton2
parents:
diff changeset
401
1
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
402 def onDisconnectRequest(self, e):
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
403 self.bridge.disconnect()
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
404
0
goffi@necton2
parents:
diff changeset
405 def __updateStatus(self):
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
406 show = filter(lambda x:x[1] == self.statusBox.GetValue(), const_STATUS)[0][0]
0
goffi@necton2
parents:
diff changeset
407 status = self.statusTxt.GetValue()
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
408 self.bridge.setPresence(show=show, statuses={'default':status}) #FIXME: manage multilingual statuses
0
goffi@necton2
parents:
diff changeset
409
goffi@necton2
parents:
diff changeset
410 def onStatusChange(self, e):
goffi@necton2
parents:
diff changeset
411 debug("Status change request")
goffi@necton2
parents:
diff changeset
412 self.__updateStatus()
goffi@necton2
parents:
diff changeset
413
goffi@necton2
parents:
diff changeset
414 def onParam(self, e):
goffi@necton2
parents:
diff changeset
415 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
416 param=Param(self)
0
goffi@necton2
parents:
diff changeset
417
goffi@necton2
parents:
diff changeset
418 def onExit(self, e):
goffi@necton2
parents:
diff changeset
419 self.Close()
goffi@necton2
parents:
diff changeset
420
goffi@necton2
parents:
diff changeset
421 def onAddContact(self, e):
goffi@necton2
parents:
diff changeset
422 debug("Add contact request")
goffi@necton2
parents:
diff changeset
423 dlg = wx.TextEntryDialog(
goffi@necton2
parents:
diff changeset
424 self, 'Please enter new contact JID',
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 36
diff changeset
425 'Adding a contact', 'name@server.tld')
0
goffi@necton2
parents:
diff changeset
426
goffi@necton2
parents:
diff changeset
427 if dlg.ShowModal() == wx.ID_OK:
goffi@necton2
parents:
diff changeset
428 jid=JID(dlg.GetValue())
goffi@necton2
parents:
diff changeset
429 if jid.is_valid():
goffi@necton2
parents:
diff changeset
430 self.bridge.addContact(jid.short)
goffi@necton2
parents:
diff changeset
431 else:
goffi@necton2
parents:
diff changeset
432 error ("'%s' is an invalid JID !", jid)
goffi@necton2
parents:
diff changeset
433 #TODO: notice the user
goffi@necton2
parents:
diff changeset
434
goffi@necton2
parents:
diff changeset
435 dlg.Destroy()
goffi@necton2
parents:
diff changeset
436
goffi@necton2
parents:
diff changeset
437 def onRemoveContact(self, e):
goffi@necton2
parents:
diff changeset
438 debug("Remove contact request")
goffi@necton2
parents:
diff changeset
439 target = self.contactList.getSelection()
goffi@necton2
parents:
diff changeset
440 if not target:
goffi@necton2
parents:
diff changeset
441 dlg = wx.MessageDialog(self, "You haven't selected any contact !",
goffi@necton2
parents:
diff changeset
442 'Error',
goffi@necton2
parents:
diff changeset
443 wx.OK | wx.ICON_ERROR
goffi@necton2
parents:
diff changeset
444 )
goffi@necton2
parents:
diff changeset
445 dlg.ShowModal()
goffi@necton2
parents:
diff changeset
446 dlg.Destroy()
goffi@necton2
parents:
diff changeset
447 return
goffi@necton2
parents:
diff changeset
448
42
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
449 dlg = wx.MessageDialog(self, "Are you sure you want to delete %s from your roster list ?" % target.short,
0
goffi@necton2
parents:
diff changeset
450 'Contact suppression',
goffi@necton2
parents:
diff changeset
451 wx.YES_NO | wx.ICON_QUESTION
goffi@necton2
parents:
diff changeset
452 )
goffi@necton2
parents:
diff changeset
453
goffi@necton2
parents:
diff changeset
454 if dlg.ShowModal() == wx.ID_YES:
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 42
diff changeset
455 info("Unsubscribing %s presence", target.short)
0
goffi@necton2
parents:
diff changeset
456 self.bridge.delContact(target.short)
goffi@necton2
parents:
diff changeset
457
goffi@necton2
parents:
diff changeset
458 dlg.Destroy()
goffi@necton2
parents:
diff changeset
459
42
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
460 def onShowProfile(self, e):
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
461 debug("Show contact's profile request")
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
462 target = self.contactList.getSelection()
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
463 if not target:
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
464 dlg = wx.MessageDialog(self, "You haven't selected any contact !",
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
465 'Error',
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
466 wx.OK | wx.ICON_ERROR
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
467 )
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
468 dlg.ShowModal()
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
469 dlg.Destroy()
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
470 return
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
471 id = self.bridge.getProfile(target.short)
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
472 self.current_action_ids.add(id)
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
473 self.current_action_ids_cb[id] = self.onProfileReceived
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
474
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
475 def onProfileReceived(self, data):
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
476 """Called when a profile is received"""
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
477 debug ('Profile received: [%s]' % data)
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
478 profile=Profile(self, data)
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
479
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
480
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
481 def onFindGateways(self, e):
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
482 debug("Find Gateways request")
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
483 id = self.bridge.findGateways(self.whoami.domain)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents: 25
diff changeset
484 self.current_action_ids.add(id)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents: 25
diff changeset
485 self.current_action_ids_cb[id] = self.onGatewaysFound
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents: 25
diff changeset
486
42
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
487 def onGatewaysFound(self, data):
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents: 25
diff changeset
488 """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
489 target = data['__private__']['target']
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
490 del data['__private__']
874de3020e1c Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents: 38
diff changeset
491 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
492
0
goffi@necton2
parents:
diff changeset
493 def onClose(self, e):
goffi@necton2
parents:
diff changeset
494 info("Exiting...")
goffi@necton2
parents:
diff changeset
495 e.Skip()
11
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
496
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
497 def onTrayClick(self, e):
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
498 debug("Tray Click")
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
499 if self.IsShown():
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
500 self.Hide()
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
501 else:
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
502 self.Show()
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
503 self.Raise()
37153f3a3dc1 wix: Tray Icon
Goffi <goffi@goffi.org>
parents: 1
diff changeset
504 e.Skip()
0
goffi@necton2
parents:
diff changeset
505