Mercurial > libervia-web
annotate src/browser/sat_browser/contact_panel.py @ 660:267761bf7f08 frontends_multi_profiles
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
- ContactPanels become the generic class for all lists of contacts
- OccupantsList will be removed
- need to implements specials icons (e.g. for games) in ContactBox
- ContactBox now manage a display arguments to set which data we want to display
- ContactsPanel.display renamed to setList
- ContactBox style can be changed when instaciating parent ContactsPanel
- muc_contact CSS class is used for list of MUC occupants
Not fully functionnal yet
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Feb 2015 22:53:27 +0100 |
parents | 6d3142b782c3 |
children | 2201ff543a05 |
rev | line source |
---|---|
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
340 | 5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org> |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
10 # (at your option) any later version. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
15 # GNU Affero General Public License for more details. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
20 """ Contacts / jids related panels """ |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
21 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
22 import pyjd # this is dummy in pyjs |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
23 from sat.core.log import getLogger |
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
24 log = getLogger(__name__) |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
25 from sat_frontends.tools import jid |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
439
diff
changeset
|
26 |
33 | 27 from pyjamas.ui.AbsolutePanel import AbsolutePanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from pyjamas.ui.VerticalPanel import VerticalPanel |
33 | 29 from pyjamas.ui.HTML import HTML |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
30 |
467 | 31 import html_tools |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
32 import contact_widget |
433
bbdbee25123a
import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents:
412
diff
changeset
|
33 from constants import Const as C |
20 | 34 |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
206
diff
changeset
|
35 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
36 # FIXME: must be removed |
33 | 37 class Occupant(HTML): |
38 """Occupant of a MUC room""" | |
39 | |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
40 def __init__(self, nick, state=None, special=""): |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
41 """ |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
42 @param nick: the user nickname |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
43 @param state: the user chate state (XEP-0085) |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
44 @param special: a string of symbols (e.g: for activities) |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
45 """ |
573
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
46 HTML.__init__(self, StyleName="occupant") |
33 | 47 self.nick = nick |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
48 self._state = state |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
49 self.special = special |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
50 self._refresh() |
35 | 51 |
52 def __str__(self): | |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
53 return self.nick |
33 | 54 |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
55 def setState(self, state): |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
56 self._state = state |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
57 self._refresh() |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
58 |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
59 def addSpecial(self, special): |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
60 """@param special: unicode""" |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
61 if special not in self.special: |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
62 self.special += special |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
63 self._refresh() |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
64 |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
65 def removeSpecials(self, special): |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
66 """@param special: unicode or list""" |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
67 if not isinstance(special, list): |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
68 special = [special] |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
69 for symbol in special: |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
70 self.special = self.special.replace(symbol, "") |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
71 self._refresh() |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
72 |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
73 def _refresh(self): |
433
bbdbee25123a
import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents:
412
diff
changeset
|
74 state = (' %s' % C.MUC_USER_STATES[self._state]) if self._state else '' |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
75 special = "" if len(self.special) == 0 else " %s" % self.special |
573
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
76 self.setHTML("%s%s%s" % (html_tools.html_sanitize(self.nick), special, state)) |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
77 |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
206
diff
changeset
|
78 |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
79 class ContactsPanel(VerticalPanel): |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
80 """ContactList graphic representation |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
81 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
82 Special features like popup menu panel or changing the contact states must be done in a sub-class. |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
83 """ |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
84 |
660
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
85 def __init__(self, parent, on_click=None, handle_menu=True, contacts_style=None, contacts_display=C.CONTACT_DEFAULT_DISPLAY): |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
86 """ |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
87 @param on_click (callable): click callback (used if ContactBox is created) |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
88 @param handle_menu (bool): if True, bind a popup menu to the avatar (used if ContactBox is created) |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
89 """ # FIXME |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
90 VerticalPanel.__init__(self) |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
91 self._parent = parent |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
92 self.host = parent.host |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
93 self._contacts = {} # entity jid to ContactBox map |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
94 self.click_listener = None |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
95 self.handle_menu = handle_menu |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
96 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
97 if on_click is not None: |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
98 self.onClick = on_click |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
99 |
660
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
100 self.contacts_style=contacts_style |
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
101 self.contacts_display = contacts_display |
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
102 |
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
103 def setList(self, jids): |
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
104 """set all contacts in the list in one shot. |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
105 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
106 @param jids (list[jid.JID]): jids to display (the order is kept) |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
107 @param name (unicode): optional name of the contact |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
108 """ |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
109 # FIXME: we do a full clear and add boxes after, we should only remove recently hidden boxes and add new ones, and re-order |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
110 current = [box.jid for box in self.children if isinstance(box, contact_widget.ContactBox)] |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
111 if current == jids: |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
112 # the display doesn't change |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
113 return |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
114 self.clear() |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
115 for jid_ in jids: |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
116 assert isinstance(jid_, jid.JID) |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
117 box = self.getContactBox(jid_) |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
118 VerticalPanel.append(self, box) |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
119 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
120 def isContactPresent(self, contact_jid): |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
121 """Return True if a contact is present in the panel""" |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
122 return contact_jid in self._contacts |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
123 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
124 def getContacts(self): |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
125 return self._contacts |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
126 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
127 def getContactBox(self, contact_jid): |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
128 """get the Contactbox of a contact |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
129 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
130 if the Contactbox doesn't exists, it will be created |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
131 @param contact_jid (jid.JID): the contact |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
132 @return: ContactBox instance |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
133 """ |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
134 try: |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
135 return self._contacts[contact_jid.bare] |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
136 except KeyError: |
660
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
137 box = contact_widget.ContactBox(self, contact_jid, style_name=self.contacts_style, display=self.contacts_display) |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
138 self._contacts[contact_jid.bare] = box |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
139 return box |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
140 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
141 def updateAvatar(self, jid_, url): |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
142 """Update the avatar of the given contact |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
143 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
144 @param jid_ (jid.JID): contact jid |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
145 @param url (unicode): image url |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
146 """ |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
147 try: |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
148 self.getContactBox(jid_).updateAvatar(url) |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
149 except TypeError: |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
150 pass |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
151 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
152 def updateNick(self, jid_, new_nick): |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
153 """Update the avatar of the given contact |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
154 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
155 @param jid_ (jid.JID): contact jid |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
156 @param new_nick (unicode): new nick of the contact |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
157 """ |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
158 try: |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
159 self.getContactBox(jid_).updateNick(new_nick) |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
160 except TypeError: |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
161 pass |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
162 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
163 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
164 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
165 # FIXME: must be removed and ContactsPanel must be used instead |
33 | 166 class OccupantsList(AbsolutePanel): |
167 """Panel user to show occupants of a room""" | |
168 | |
169 def __init__(self): | |
170 AbsolutePanel.__init__(self) | |
35 | 171 self.occupants_list = {} |
33 | 172 self.setStyleName('occupantsList') |
173 | |
174 def addOccupant(self, nick): | |
584
0a06cf833f5a
browser_side: various improvements, especially for MUC
souliane <souliane@mailoo.org>
parents:
577
diff
changeset
|
175 if nick in self.occupants_list: |
0a06cf833f5a
browser_side: various improvements, especially for MUC
souliane <souliane@mailoo.org>
parents:
577
diff
changeset
|
176 return |
35 | 177 _occupant = Occupant(nick) |
178 self.occupants_list[nick] = _occupant | |
179 self.add(_occupant) | |
33 | 180 |
35 | 181 def removeOccupant(self, nick): |
182 try: | |
183 self.remove(self.occupants_list[nick]) | |
184 except KeyError: | |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
185 log.error("trying to remove an unexisting nick") |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
186 |
573
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
187 def getOccupantBox(self, nick): |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
188 """Get the widget element of the given nick. |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
189 |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
190 @return: Occupant |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
191 """ |
577
e1a773a64fb6
browser_side: fixes the display of MUC occupants presences
souliane <souliane@mailoo.org>
parents:
573
diff
changeset
|
192 try: |
e1a773a64fb6
browser_side: fixes the display of MUC occupants presences
souliane <souliane@mailoo.org>
parents:
573
diff
changeset
|
193 return self.occupants_list[nick] |
e1a773a64fb6
browser_side: fixes the display of MUC occupants presences
souliane <souliane@mailoo.org>
parents:
573
diff
changeset
|
194 except KeyError: |
e1a773a64fb6
browser_side: fixes the display of MUC occupants presences
souliane <souliane@mailoo.org>
parents:
573
diff
changeset
|
195 return None |
573
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
196 |
35 | 197 def clear(self): |
198 self.occupants_list.clear() | |
199 AbsolutePanel.clear(self) | |
200 | |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
201 def updateSpecials(self, occupants=[], html=""): |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
202 """Set the specified html "symbol" to the listed occupants, |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
203 and eventually remove it from the others (if they got it). |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
204 This is used for example to visualize who is playing a game. |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
205 @param occupants: list of the occupants that need the symbol |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
206 @param html: unicode symbol (actually one character or more) |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
207 or a list to assign different symbols of the same family. |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
208 """ |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
209 index = 0 |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
210 special = html |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
211 for occupant in self.occupants_list.keys(): |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
212 if occupant in occupants: |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
213 if isinstance(html, list): |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
214 special = html[index] |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
215 index = (index + 1) % len(html) |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
216 self.occupants_list[occupant].addSpecial(special) |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
217 else: |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
218 self.occupants_list[occupant].removeSpecials(html) |