annotate src/browser/sat_browser/contact_panel.py @ 659:8e7d4de56e75 frontends_multi_profiles

browser_side: allow to drop a widget in the "+" tab
author souliane <souliane@mailoo.org>
date Fri, 27 Feb 2015 16:05:28 +0100
parents 6d3142b782c3
children 267761bf7f08
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ce5b33f499c5 dates update
Goffi <goffi@goffi.org>
parents: 339
diff changeset
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
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
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
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
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
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
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
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
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
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
37 class Occupant(HTML):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
38 """Occupant of a MUC room"""
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
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
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
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
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
51
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
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
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
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
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
85 def __init__(self, parent, on_click=None, handle_menu=True):
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
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
100 def display(self, 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
101 """Display a contact in the list.
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
102
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
103 @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
104 @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
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 # 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
107 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
108 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
109 # 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
110 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
111 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
112 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
113 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
114 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
115 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
116
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 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
118 """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
119 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
120
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 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
122 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
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 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
125 """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
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 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
128 @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
129 @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
130 """
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 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
132 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
133 except KeyError:
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
134 box = contact_widget.ContactBox(self, contact_jid)
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
135 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
136 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
137
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 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
139 """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
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 @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
142 @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
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 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
145 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
146 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
147 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
148
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 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
150 """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
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 @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
153 @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
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 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
156 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
157 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
158 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
159
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
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
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 # FIXME: must be removed and ContactsPanel must be used instead
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
163 class OccupantsList(AbsolutePanel):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
164 """Panel user to show occupants of a room"""
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
165
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
166 def __init__(self):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
167 AbsolutePanel.__init__(self)
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
168 self.occupants_list = {}
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
169 self.setStyleName('occupantsList')
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
170
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
171 def addOccupant(self, nick):
584
0a06cf833f5a browser_side: various improvements, especially for MUC
souliane <souliane@mailoo.org>
parents: 577
diff changeset
172 if nick in self.occupants_list:
0a06cf833f5a browser_side: various improvements, especially for MUC
souliane <souliane@mailoo.org>
parents: 577
diff changeset
173 return
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
174 _occupant = Occupant(nick)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
175 self.occupants_list[nick] = _occupant
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
176 self.add(_occupant)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
177
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
178 def removeOccupant(self, nick):
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
179 try:
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
180 self.remove(self.occupants_list[nick])
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
181 except KeyError:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
182 log.error("trying to remove an unexisting nick")
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
183
573
12823bcbd05b browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents: 491
diff changeset
184 def getOccupantBox(self, nick):
12823bcbd05b browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents: 491
diff changeset
185 """Get the widget element of the given nick.
12823bcbd05b browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents: 491
diff changeset
186
12823bcbd05b browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents: 491
diff changeset
187 @return: Occupant
12823bcbd05b browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents: 491
diff changeset
188 """
577
e1a773a64fb6 browser_side: fixes the display of MUC occupants presences
souliane <souliane@mailoo.org>
parents: 573
diff changeset
189 try:
e1a773a64fb6 browser_side: fixes the display of MUC occupants presences
souliane <souliane@mailoo.org>
parents: 573
diff changeset
190 return self.occupants_list[nick]
e1a773a64fb6 browser_side: fixes the display of MUC occupants presences
souliane <souliane@mailoo.org>
parents: 573
diff changeset
191 except KeyError:
e1a773a64fb6 browser_side: fixes the display of MUC occupants presences
souliane <souliane@mailoo.org>
parents: 573
diff changeset
192 return None
573
12823bcbd05b browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents: 491
diff changeset
193
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
194 def clear(self):
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
195 self.occupants_list.clear()
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
196 AbsolutePanel.clear(self)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
197
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
198 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
199 """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
200 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
201 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
202 @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
203 @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
204 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
205 """
273
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
206 index = 0
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
207 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
208 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
209 if occupant in occupants:
273
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
210 if isinstance(html, list):
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
211 special = html[index]
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
212 index = (index + 1) % len(html)
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
213 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
214 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
215 self.occupants_list[occupant].removeSpecials(html)