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