comparison src/browser/sat_browser/base_panels.py @ 647:e0021d571eef frontends_multi_profiles

browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
author Goffi <goffi@goffi.org>
date Thu, 26 Feb 2015 13:10:46 +0100
parents 32dbbc941123
children
comparison
equal deleted inserted replaced
646:9972a24592b0 647:e0021d571eef
20 import pyjd # this is dummy in pyjs 20 import pyjd # this is dummy in pyjs
21 from sat.core.log import getLogger 21 from sat.core.log import getLogger
22 log = getLogger(__name__) 22 log = getLogger(__name__)
23 from sat.core.i18n import _ 23 from sat.core.i18n import _
24 from sat_frontends.tools import strings 24 from sat_frontends.tools import strings
25 from sat_frontends.tools import jid
25 26
26 from pyjamas.ui.AbsolutePanel import AbsolutePanel 27 from pyjamas.ui.AbsolutePanel import AbsolutePanel
27 from pyjamas.ui.VerticalPanel import VerticalPanel 28 from pyjamas.ui.VerticalPanel import VerticalPanel
28 from pyjamas.ui.HorizontalPanel import HorizontalPanel 29 from pyjamas.ui.HorizontalPanel import HorizontalPanel
29 from pyjamas.ui.Button import Button 30 from pyjamas.ui.Button import Button
37 from pyjamas.ui.FocusListener import FocusHandler 38 from pyjamas.ui.FocusListener import FocusHandler
38 from pyjamas.ui.ClickListener import ClickHandler 39 from pyjamas.ui.ClickListener import ClickHandler
39 from pyjamas import DOM 40 from pyjamas import DOM
40 41
41 import html_tools 42 import html_tools
43 import base_widget
42 from constants import Const as C 44 from constants import Const as C
45
43 46
44 47
45 class Occupant(HTML): 48 class Occupant(HTML):
46 """Occupant of a MUC room""" 49 """Occupant of a MUC room"""
47 50
82 state = (' %s' % C.MUC_USER_STATES[self._state]) if self._state else '' 85 state = (' %s' % C.MUC_USER_STATES[self._state]) if self._state else ''
83 special = "" if len(self.special) == 0 else " %s" % self.special 86 special = "" if len(self.special) == 0 else " %s" % self.special
84 self.setHTML("%s%s%s" % (html_tools.html_sanitize(self.nick), special, state)) 87 self.setHTML("%s%s%s" % (html_tools.html_sanitize(self.nick), special, state))
85 88
86 89
90 class ContactsPanel(VerticalPanel):
91 """ContactList graphic representation
92
93 Special features like popup menu panel or changing the contact states must be done in a sub-class.
94 """
95
96 def __init__(self, parent, on_click=None, handle_menu=True):
97 """
98 @param on_click (callable): click callback (used if ContactBox is created)
99 @param handle_menu (bool): if True, bind a popup menu to the avatar (used if ContactBox is created)
100 """ # FIXME
101 VerticalPanel.__init__(self)
102 self._parent = parent
103 self.host = parent.host
104 self._contacts = {} # entity jid to ContactBox map
105 self.click_listener = None
106 self.handle_menu = handle_menu
107
108 if on_click is not None:
109 self.onClick = on_click
110
111 def display(self, jids):
112 """Display a contact in the list.
113
114 @param jids (list[jid.JID]): jids to display (the order is kept)
115 @param name (unicode): optional name of the contact
116 """
117 # FIXME: we do a full clear and add boxes after, we should only remove recently hidden boxes and add new ones, and re-order
118 current = [box.jid for box in self.children if isinstance(box, base_widget.ContactBox)]
119 if current == jids:
120 # the display doesn't change
121 return
122 self.clear()
123 for jid_ in jids:
124 assert isinstance(jid_, jid.JID)
125 box = self.getContactBox(jid_)
126 VerticalPanel.append(self, box)
127
128 def isContactPresent(self, contact_jid):
129 """Return True if a contact is present in the panel"""
130 return contact_jid in self._contacts
131
132 def getContacts(self):
133 return self._contacts
134
135 def getContactBox(self, contact_jid):
136 """get the Contactbox of a contact
137
138 if the Contactbox doesn't exists, it will be created
139 @param contact_jid (jid.JID): the contact
140 @return: ContactBox instance
141 """
142 try:
143 return self._contacts[contact_jid.bare]
144 except KeyError:
145 box = base_widget.ContactBox(self, contact_jid)
146 self._contacts[contact_jid.bare] = box
147 return box
148
149 def updateAvatar(self, jid_, url):
150 """Update the avatar of the given contact
151
152 @param jid_ (jid.JID): contact jid
153 @param url (unicode): image url
154 """
155 try:
156 self.getContactBox(jid_).updateAvatar(url)
157 except TypeError:
158 pass
159
160 def updateNick(self, jid_, new_nick):
161 """Update the avatar of the given contact
162
163 @param jid_ (jid.JID): contact jid
164 @param new_nick (unicode): new nick of the contact
165 """
166 try:
167 self.getContactBox(jid_).updateNick(new_nick)
168 except TypeError:
169 pass
170
171
172
173 # FIXME: must be removed and ContactsPanel must be used instead
87 class OccupantsList(AbsolutePanel): 174 class OccupantsList(AbsolutePanel):
88 """Panel user to show occupants of a room""" 175 """Panel user to show occupants of a room"""
89 176
90 def __init__(self): 177 def __init__(self):
91 AbsolutePanel.__init__(self) 178 AbsolutePanel.__init__(self)