Mercurial > libervia-web
comparison src/browser/sat_browser/contact_widget.py @ 687:3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
- Chat uses presence and avatar listener, remove unecessary methods for MUC and contact states
- contact list doesn't add unecessary ContactBox (e.g for MUC bare entities)
- nick, message alerts are handled directly in ContactLabel
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 23 Mar 2015 09:35:46 +0100 |
parents | 9877607c719a |
children | 76a67d04c63e |
comparison
equal
deleted
inserted
replaced
686:90a5a5af2550 | 687:3845a086f0b3 |
---|---|
48 """ | 48 """ |
49 # TODO: add a listener for nick changes | 49 # TODO: add a listener for nick changes |
50 HTML.__init__(self) | 50 HTML.__init__(self) |
51 self.host = host | 51 self.host = host |
52 self.jid = jid_ | 52 self.jid = jid_ |
53 if "nick" in display: | |
54 self.nick = self.host.contact_lists[C.PROF_KEY_NONE].getCache(self.jid, "nick") | |
55 self.display = display | 53 self.display = display |
56 self.alert = False | 54 self.alert = False |
57 self.refresh() | |
58 self.setStyleName('contactLabel') | 55 self.setStyleName('contactLabel') |
59 | 56 |
60 def refresh(self): | 57 def update(self): |
61 alert_html = "<strong>(*)</strong> " if self.alert else "" | 58 clist = self.host.contact_list |
59 alert_html = "<strong>(*)</strong> " if self.jid in clist._alerts else "" | |
60 | |
62 contact_raw = None | 61 contact_raw = None |
63 for disp in self.display: | 62 for disp in self.display: |
64 if disp == "jid": | 63 if disp == "jid": |
65 contact_raw = unicode(self.jid) | 64 contact_raw = unicode(self.jid) |
66 elif disp == "nick": | 65 elif disp == "nick": |
67 contact_raw = self.nick | 66 clist = self.host.contact_list |
67 contact_raw = html_tools.html_sanitize(clist.getCache(self.jid, "nick")) | |
68 elif disp == "bare": | 68 elif disp == "bare": |
69 contact_raw = unicode(self.jid.bare) | 69 contact_raw = unicode(self.jid.bare) |
70 elif disp == "resource": | 70 elif disp == "resource": |
71 contact_raw = self.jid.resource | 71 contact_raw = self.jid.resource |
72 else: | 72 else: |
75 break | 75 break |
76 if not contact_raw: | 76 if not contact_raw: |
77 log.error(u"Could not find a contact display for jid {jid} (display: {display})".format(jid=self.jid, display=self.display)) | 77 log.error(u"Could not find a contact display for jid {jid} (display: {display})".format(jid=self.jid, display=self.display)) |
78 contact_raw = "UNNAMED" | 78 contact_raw = "UNNAMED" |
79 contact_html = html_tools.html_sanitize(contact_raw) | 79 contact_html = html_tools.html_sanitize(contact_raw) |
80 | |
80 html = "%(alert)s%(contact)s" % {'alert': alert_html, | 81 html = "%(alert)s%(contact)s" % {'alert': alert_html, |
81 'contact': contact_html} | 82 'contact': contact_html} |
82 self.setHTML(html) | 83 self.setHTML(html) |
83 | |
84 def updateNick(self, new_nick): | |
85 """Change the current nick | |
86 | |
87 @param new_nick(unicode): new nick to use | |
88 """ | |
89 self.nick = new_nick | |
90 self.refresh() | |
91 | |
92 def setAlert(self, alert): | |
93 """Show a visual indicator | |
94 | |
95 @param alert: True if alert must be shown | |
96 """ | |
97 self.alert = alert | |
98 self.refresh() | |
99 | 84 |
100 | 85 |
101 class ContactMenuBar(base_widget.WidgetMenuBar): | 86 class ContactMenuBar(base_widget.WidgetMenuBar): |
102 | 87 |
103 def onBrowserEvent(self, event): | 88 def onBrowserEvent(self, event): |
130 ClickHandler.__init__(self) | 115 ClickHandler.__init__(self) |
131 libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", host) | 116 libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", host) |
132 self.jid = jid_ | 117 self.jid = jid_ |
133 self.label = ContactLabel(host, self.jid, display=display) | 118 self.label = ContactLabel(host, self.jid, display=display) |
134 self.avatar = ContactMenuBar(self, host) if plugin_menu_context else Image() | 119 self.avatar = ContactMenuBar(self, host) if plugin_menu_context else Image() |
135 self.states = HTML("") | 120 self.states = HTML() |
136 try: # FIXME: dirty hack to force using an Image when the menu is actually empty | 121 try: # FIXME: dirty hack to force using an Image when the menu is actually empty |
137 self.avatar.items[0] | 122 self.avatar.items[0] |
138 except IndexError: | 123 except IndexError: |
139 self.avatar = Image() | 124 self.avatar = Image() |
140 self.updateAvatar(host.getAvatarURL(self.jid.bare)) | |
141 self.add(self.avatar) | 125 self.add(self.avatar) |
142 self.add(self.label) | 126 self.add(self.label) |
143 self.add(self.states) | 127 self.add(self.states) |
128 self.update() | |
144 self.addClickListener(self) | 129 self.addClickListener(self) |
145 | 130 |
146 def setAlert(self, alert): | 131 def update(self): |
147 """Show a visual indicator. | 132 """Update the display. |
148 | 133 |
149 @param alert (bool): True if alert indicator show be shown | 134 @param with_bare (bool): if True, ignore the resource and update with bare information. |
150 """ | 135 """ |
151 self.label.setAlert(alert) | 136 self.avatar.setUrl(self.host.getAvatarURL(self.jid)) |
152 | 137 |
153 def updateAvatar(self, url): | 138 self.label.update() |
154 """Update the avatar. | 139 clist = self.host.contact_list |
155 | 140 show = clist.getCache(self.jid, C.PRESENCE_SHOW) |
156 @param url (unicode): image url | 141 if show is None: |
157 """ | 142 show = C.PRESENCE_UNAVAILABLE |
158 self.avatar.setUrl(url) | 143 html_tools.setPresenceStyle(self.label, show) |
159 | |
160 def updateNick(self, new_nick): | |
161 """Update the nickname. | |
162 | |
163 @param new_nick (unicode): new nickname to use | |
164 """ | |
165 self.label.updateNick(html_tools.html_sanitize(new_nick)) | |
166 | |
167 def updateStates(self, states): | |
168 """Update the states. | |
169 | |
170 @param states (dict{unicode: unicode}): new states | |
171 """ | |
172 self.states.setHTML(u''.join(states.values())) | |
173 | 144 |
174 def onClick(self, sender): | 145 def onClick(self, sender): |
175 try: | 146 try: |
176 self.parent.onClick(self.jid.bare) | 147 self.parent.onClick(self.jid) |
177 except (AttributeError, TypeError): | 148 except (AttributeError, TypeError): |
178 pass | 149 pass |
179 else: | |
180 self.setAlert(False) | |
181 | 150 |
182 quick_menus.QuickMenusManager.addDataCollector(C.MENU_JID_CONTEXT, lambda caller, dummy: {'jid': unicode(caller.jid.bare)}) | 151 quick_menus.QuickMenusManager.addDataCollector(C.MENU_JID_CONTEXT, lambda caller, dummy: {'jid': unicode(caller.jid.bare)}) |