annotate src/browser/sat_browser/contact_widget.py @ 671:2201ff543a05 frontends_multi_profiles

browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
author souliane <souliane@mailoo.org>
date Mon, 09 Mar 2015 16:30:06 +0100
parents 267761bf7f08
children 849ffb24d5bf
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: 334
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: 334
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: 334
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: 334
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: 334
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: 334
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: 334
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: 334
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: 334
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: 334
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: 334
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
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 232
diff changeset
20 import pyjd # this is dummy in pyjs
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 432
diff changeset
21 from sat.core.log import getLogger
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 432
diff changeset
22 log = getLogger(__name__)
618
698bdb84f6a7 browser_side: always display the main tab bar with a "+" button to add a new tab
souliane <souliane@mailoo.org>
parents: 617
diff changeset
23
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
24 from sat.core import exceptions
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.VerticalPanel import VerticalPanel
543
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 536
diff changeset
26 from pyjamas.ui.HTML import HTML
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: 637
diff changeset
27 from pyjamas.ui.Image import Image
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
28 from pyjamas.ui.ClickListener import ClickHandler
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: 637
diff changeset
29 from constants import Const as C
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: 637
diff changeset
30 import html_tools
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
31 import base_widget
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
32 import libervia_widget
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: 637
diff changeset
33
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: 637
diff changeset
34 unicode = str # XXX: pyjama doesn't manage unicode
370
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
35
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
36
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: 637
diff changeset
37 class ContactLabel(HTML):
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: 637
diff changeset
38 """Display a contact in HTML, selecting best display (jid/nick/etc)"""
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: 637
diff changeset
39
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
40 def __init__(self, host, jid_, display=C.CONTACT_DEFAULT_DISPLAY):
671
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
41 """
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
42
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
43 @param host (SatWebFrontend): host instance
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
44 @param jid_ (jid.JID): contact JID
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
45 @param display (tuple): prioritize the display methods of the contact's
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
46 label with values in ("jid", "nick", "bare", "resource").
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
47 """
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: 637
diff changeset
48 # TODO: add a listener for nick changes
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: 637
diff changeset
49 HTML.__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: 637
diff changeset
50 self.host = host
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
51 self.jid = jid_
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
52 if "nick" in display:
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
53 self.nick = self.host.contact_lists[C.PROF_KEY_NONE].getCache(self.jid, "nick")
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
54 self.display = 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: 637
diff changeset
55 self.alert = False
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: 637
diff changeset
56 self.refresh()
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: 637
diff changeset
57 self.setStyleName('contactLabel')
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: 637
diff changeset
58
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: 637
diff changeset
59 def refresh(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: 637
diff changeset
60 alert_html = "<strong>(*)</strong>&nbsp;" if self.alert else ""
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
61 contact_raw = None
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
62 for disp in self.display:
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
63 if disp == "jid":
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
64 contact_raw = unicode(self.jid)
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
65 elif disp == "nick":
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
66 contact_raw = self.nick
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
67 elif disp == "bare":
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
68 contact_raw = unicode(self.jid.bare)
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
69 elif disp == "resource":
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
70 contact_raw = self.jid.resource
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
71 else:
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
72 raise exceptions.InternalError(u"Unknown display argument [{}]".format(disp))
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
73 if contact_raw:
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
74 break
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
75 if not contact_raw:
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
76 log.error(u"Counld not find a contact display for jid {jid} (display: {display})".format(jid=self.jid, display=self.display))
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
77 contact_raw = "UNNAMED"
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
78 contact_html = html_tools.html_sanitize(contact_raw)
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: 637
diff changeset
79 html = "%(alert)s%(contact)s" % {'alert': alert_html,
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: 637
diff changeset
80 'contact': contact_html}
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: 637
diff changeset
81 self.setHTML(html)
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: 637
diff changeset
82
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: 637
diff changeset
83 def updateNick(self, 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: 637
diff changeset
84 """Change the current 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: 637
diff changeset
85
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: 637
diff changeset
86 @param new_nick(unicode): new nick to use
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: 637
diff changeset
87 """
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: 637
diff changeset
88 self.nick = 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: 637
diff changeset
89 self.refresh()
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: 637
diff changeset
90
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: 637
diff changeset
91 def setAlert(self, alert):
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: 637
diff changeset
92 """Show a visual indicator
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: 637
diff changeset
93
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: 637
diff changeset
94 @param alert: True if alert must be shown
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: 637
diff changeset
95 """
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: 637
diff changeset
96 self.alert = alert
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: 637
diff changeset
97 self.refresh()
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: 637
diff changeset
98
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: 637
diff changeset
99
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
100 class ContactMenuBar(base_widget.WidgetMenuBar):
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: 637
diff changeset
101
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: 637
diff changeset
102 def onBrowserEvent(self, event):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
103 base_widget.WidgetMenuBar.onBrowserEvent(self, event)
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: 637
diff changeset
104 event.stopPropagation() # prevent opening the chat dialog
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: 637
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: 637
diff changeset
106 @classmethod
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: 637
diff changeset
107 def getCategoryHTML(cls, menu_name_i18n, type_):
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: 637
diff changeset
108 return '<img src="%s"/>' % C.DEFAULT_AVATAR_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: 637
diff changeset
109
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: 637
diff changeset
110 def setUrl(self, 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: 637
diff changeset
111 """Set the URL of the contact avatar."""
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: 637
diff changeset
112 self.items[0].setHTML('<img src="%s" />' % 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: 637
diff changeset
113
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: 637
diff changeset
114
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
115 class ContactBox(VerticalPanel, ClickHandler, libervia_widget.DragLabel):
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: 637
diff changeset
116
671
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
117 def __init__(self, host, jid_, style_name=None, menu_types=None, 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: 637
diff changeset
118 """
671
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
119 @param host (SatWebFrontend): host instance
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: 637
diff changeset
120 @param jid_ (jid.JID): contact JID
671
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
121 @param style_name (unicode): CSS style name
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
122 @param menu_types (tuple): define the menu types that fit this
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
123 contact panel, with values from the menus type constants.
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
124 @param contacts_display (tuple): prioritize the display methods of the
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
125 contact's label with values in ("jid", "nick", "bare", "resource").
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
126
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: 637
diff changeset
127 """
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
128 VerticalPanel.__init__(self, StyleName=style_name or 'contactBox', VerticalAlignment='middle')
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: 637
diff changeset
129 ClickHandler.__init__(self)
671
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
130 libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", host)
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
131 self.jid = jid_
671
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
132 self.label = ContactLabel(host, self.jid, display=display)
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
133 self.menu_types = menu_types
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
134 self.avatar = ContactMenuBar(self, host) if menu_types else Image()
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
135 try: # FIXME: dirty hack to force using an Image when the menu is actually empty
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
136 self.avatar.items[0]
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
137 except IndexError:
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
138 self.avatar = Image()
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
139 self.updateAvatar(host.getAvatarURL(self.jid.bare))
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: 637
diff changeset
140 self.add(self.avatar)
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: 637
diff changeset
141 self.add(self.label)
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: 637
diff changeset
142 self.addClickListener(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: 637
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: 637
diff changeset
144 def addMenus(self, menu_bar):
671
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
145 for menu_type in self.menu_types:
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
146 menu_bar.addCachedMenus(menu_type, {'jid': unicode(self.jid.bare)})
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: 637
diff changeset
147
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: 637
diff changeset
148 def setAlert(self, alert):
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: 637
diff changeset
149 """Show a visual indicator
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: 637
diff changeset
150
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: 637
diff changeset
151 @param alert: True if alert indicator show be shown"""
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: 637
diff changeset
152 self.label.setAlert(alert)
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: 637
diff changeset
153
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: 637
diff changeset
154 def updateAvatar(self, 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: 637
diff changeset
155 """Update the avatar.
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: 637
diff changeset
156
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: 637
diff changeset
157 @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: 637
diff changeset
158 """
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: 637
diff changeset
159 self.avatar.setUrl(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: 637
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: 637
diff changeset
161 def updateNick(self, 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: 637
diff changeset
162 """Update the nickname.
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: 637
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: 637
diff changeset
164 @param new_nick (unicode): new nickname to use
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: 637
diff changeset
165 """
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: 637
diff changeset
166 self.label.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: 637
diff changeset
167
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: 637
diff changeset
168 def onClick(self, sender):
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: 637
diff changeset
169 try:
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
170 self.parent.onClick(self.jid.bare)
671
2201ff543a05 browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents: 660
diff changeset
171 except (AttributeError, TypeError):
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: 637
diff changeset
172 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: 637
diff changeset
173 else:
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: 637
diff changeset
174 self.setAlert(False)