annotate frontends/src/wix/contact_list.py @ 1021:a836b6da2c5c

core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
author Goffi <goffi@goffi.org>
date Wed, 14 May 2014 12:51:24 +0200
parents 5a6354ff468c
children 0a9986452bba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
227
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
1 #!/usr/bin/python
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
2 # -*- coding: utf-8 -*-
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
4 # wix: a SAT frontend
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 771
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
227
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
10 # (at your option) any later version.
227
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
15 # GNU Affero General Public License for more details.
227
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
227
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 737
diff changeset
20 from sat.core.i18n import _
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import wx
227
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
22 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
736
6246eb6d64a0 frontends: define the constants with classes and inheritance instance of using __builtin__
souliane <souliane@mailoo.org>
parents: 688
diff changeset
23 from sat_frontends.wix.constants import Const
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
24 from sat.core.log import getLogger
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
25 log = getLogger(__name__)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from cgi import escape
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
27 from sat.tools.jid import JID
366
0806a65a5fa9 wix: updated paths to use media_dir
Goffi <goffi@goffi.org>
parents: 316
diff changeset
28 from os.path import join
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30
199
58f96e66ec17 wix: unicode fixes in contact list
Goffi <goffi@goffi.org>
parents: 183
diff changeset
31 class Group(unicode):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 """Class used to recognize groups"""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33
199
58f96e66ec17 wix: unicode fixes in contact list
Goffi <goffi@goffi.org>
parents: 183
diff changeset
34 class Contact(unicode):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 """Class used to recognize groups"""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 class ContactList(wx.SimpleHtmlListBox, QuickContactList):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 """Customized control to manage contacts."""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
40 def __init__(self, parent, host, type_="JID"):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 """init the contact list
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 @param parent: WxWidgets parent of the widget
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 @param host: wix main app class
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
44 @param type_: type of contact list: "JID" for the usual big jid contact list
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
45 "CUSTOM" for a customized contact list (self._presentItem must then be overrided)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 """
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 wx.SimpleHtmlListBox.__init__(self, parent, -1)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
48 QuickContactList.__init__(self)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.host = host
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
50 self.type = type_
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.__typeSwitch()
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.groups = {} #list contacts in each groups, key = group
366
0806a65a5fa9 wix: updated paths to use media_dir
Goffi <goffi@goffi.org>
parents: 316
diff changeset
53 self.empty_avatar = join(host.media_dir, 'misc/empty_avatar')
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.Bind(wx.EVT_LISTBOX, self.onSelected)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.Bind(wx.EVT_LISTBOX_DCLICK, self.onActivated)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
56
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 75
diff changeset
57 def __contains__(self, jid):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 75
diff changeset
58 return bool(self.__find_idx(jid))
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def __typeSwitch(self):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 if self.type == "JID":
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
62 self._presentItem = self._presentItemJID
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
63 elif self.type != "CUSTOM":
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
64 self._presentItem = self._presentItemDefault
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 def __find_idx(self, entity):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 """Find indexes of given contact (or groups) in contact list, manage jid
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 @return: list of indexes"""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 result=[]
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 for i in range(self.GetCount()):
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
71 if (type(entity) == JID and type(self.GetClientData(i)) == JID and self.GetClientData(i).bare == entity.bare) or\
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.GetClientData(i) == entity:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 result.append(i)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 return result
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
76 def update_jid(self, jid):
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
77 self.replace(jid)
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
78
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
79 def replace(self, contact, groups=None, attributes=None):
1000
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 812
diff changeset
80 """Add a contact to the list if doesn't exist, else update it.
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 812
diff changeset
81
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 812
diff changeset
82 @param jid (JID)
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 812
diff changeset
83 @param groups (list): list of groups or None to ignore the groups membership.
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 812
diff changeset
84 @param attributes (dict)
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 812
diff changeset
85
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 812
diff changeset
86 XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 812
diff changeset
87 """
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
88 log.debug(_("update %s") % contact)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 if not self.__find_idx(contact):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 self.add(contact, groups)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 else:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 for i in self.__find_idx(contact):
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
93 _present = self._presentItem(contact)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
94 if _present != None:
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
95 self.SetString(i, _present)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 def __eraseGroup(self, group):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 """Erase all contacts in group
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 @param group: group to erase
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 @return: True if something as been erased"""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 erased = False
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 indexes = self.__find_idx(group)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 for idx in indexes:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 while idx<self.GetCount()-1 and type(self.GetClientData(idx+1)) != Group:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 erased = True
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self.Delete(idx+1)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 return erased
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
110 def _presentGroup(self, group):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 """Make a nice presentation for the contact groups"""
199
58f96e66ec17 wix: unicode fixes in contact list
Goffi <goffi@goffi.org>
parents: 183
diff changeset
112 html = u"""-- [%s] --""" % group
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 return html
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
116 def _presentItemDefault(self, contact):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 """Make a basic presentation of string contacts in the list."""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 return contact
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
119
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
120 def _presentItemJID(self, jid):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 """Make a nice presentation of the contact in the list for JID contacts."""
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
122 name = self.getCache(jid,'name')
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
123 nick = self.getCache(jid,'nick')
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
124 _show = self.getCache(jid,'show')
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
125 if _show == None or _show == 'unavailable':
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
126 return None
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
127 show = [x for x in Const.PRESENCE if x[0] == _show][0]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
128
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 #show[0]==shortcut
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 #show[1]==human readable
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 #show[2]==color (or None)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 show_html = "<font color='%s'>[%s]</font>" % (show[2], show[1]) if show[2] else ""
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
133 status = self.getCache(jid,'status') or ''
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
134 avatar = self.getCache(jid,'avatar') or self.empty_avatar #XXX: there is a weird bug here: if the image has an extension (i.e. empty_avatar.png),
316
3a21d586dae4 wix: workaround a weird bug which crash wix while using empty_avatar, see comments for more information
Goffi <goffi@goffi.org>
parents: 228
diff changeset
135 #WxPython segfault, and it doesn't without nothing. I couldn't reproduce the case with a basic test script, so it need further investigation before reporting it
3a21d586dae4 wix: workaround a weird bug which crash wix while using empty_avatar, see comments for more information
Goffi <goffi@goffi.org>
parents: 228
diff changeset
136 #to WxPython dev. Anyway, the program crash with a segfault, not a python exception, so there is definitely something wrong with WxPython.
3a21d586dae4 wix: workaround a weird bug which crash wix while using empty_avatar, see comments for more information
Goffi <goffi@goffi.org>
parents: 228
diff changeset
137 #The case seems to happen when SimpleHtmlListBox parse the HTML with the <img> tag
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
138
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 html = """
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 <table border='0'>
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 <td>
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 <img height='64' width='64' src='%s' />
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 </td>
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 <td>
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 <b>%s</b> %s<br />
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 <i>%s</i>
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 </td>
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 </table>
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 """ % (avatar,
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
150 escape(nick or name or jid.node or jid.bare),
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 show_html,
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
152 escape(status))
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 return html
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
156 def clearContacts(self):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157 """Clear all the contact list"""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 self.Clear()
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
159
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
160 def add(self, contact, groups = None):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161 """add a contact to the list"""
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
162 log.debug (_("adding %s"),contact)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163 if not groups:
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
164 _present = self._presentItem(contact)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
165 if _present:
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
166 idx = self.Insert(_present, 0, contact)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167 else:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 for group in groups:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169 indexes = self.__find_idx(group)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170 gp_idx = 0
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171 if not indexes: #this is a new group, we have to create it
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
172 gp_idx = self.Append(self._presentGroup(group), Group(group))
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
173 else:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174 gp_idx = indexes[0]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
175
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
176 _present = self._presentItem(contact)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
177 if _present:
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
178 self.Insert(_present, gp_idx+1, contact)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
179
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
180 def setSpecial(self, special_jid, special_type, show=False):
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
181 """Set entity as a special
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
182 @param jid: jid of the entity
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
183 @param _type: special type (e.g.: "MUC")
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
184 @param show: True to display the dialog to chat with this entity
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
185 """
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
186 QuickContactList.setSpecial(self, special_jid, special_type, show)
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
187 if show:
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
188 self._showDialog(special_jid)
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
189
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
190 def _showDialog(self, jid):
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
191 """Show the dialog associated to the given jid."""
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
192 indexes = self.__find_idx(jid)
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
193 if not indexes:
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
194 return
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
195 self.DeselectAll()
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
196 self.SetSelection(indexes[0])
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
197 self.onActivated(wx.MouseEvent())
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
198
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
199 def remove(self, contact):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
200 """remove a contact from the list"""
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
201 log.debug (_("removing %s"), contact)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
202 list_idx = self.__find_idx(contact)
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
203 list_idx.reverse() #as we make some deletions, we have to reverse the order
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
204 for i in list_idx:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
205 self.Delete(i)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
206
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
207 def onSelected(self, event):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
208 """Called when a contact is selected."""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
209 data = self.getSelection()
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
210 if data == None: #we have a group
138
2f8c86488b05 wix: scrolling is not reseted anymore when clicking on a group on contact list
Goffi <goffi@goffi.org>
parents: 125
diff changeset
211 first_visible = self.GetVisibleBegin()
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
212 group = self.GetClientData(self.GetSelection())
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
213 erased = self.__eraseGroup(group)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
214 if not erased: #the group was already erased, we can add again the contacts
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
215 contacts = [JID(contact) for contact in self.host.bridge.getContactsFromGroup(group, self.host.profile)]
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
216 contacts.sort()
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
217 id_insert = self.GetSelection()+1
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
218 for contact in contacts:
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
219 _present = self._presentItem(contact)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
220 if _present:
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
221 self.Insert(_present, id_insert, contact)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
222 self.SetSelection(wx.NOT_FOUND)
138
2f8c86488b05 wix: scrolling is not reseted anymore when clicking on a group on contact list
Goffi <goffi@goffi.org>
parents: 125
diff changeset
223 self.ScrollToLine(first_visible)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
224 event.Skip(False)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
225 else:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
226 event.Skip()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
227
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
228 def onActivated(self, event):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
229 """Called when a contact is clicked or activated with keyboard."""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
230 data = self.getSelection()
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
231 self.onActivatedCB(data)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
232 event.Skip()
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
233
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
234 def getSelection(self):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
235 """Return the selected contact, or an empty string if there is not"""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
236 if self.GetSelection() == wx.NOT_FOUND:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
237 return None
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
238 data = self.GetClientData(self.GetSelection())
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
239 if type(data) == Group:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
240 return None
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
241 return data
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
242
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
243 def registerActivatedCB(self, cb):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
244 """Register a callback with manage contact activation."""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
245 self.onActivatedCB=cb
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
246