annotate src/browser/sat_browser/contact_widget.py @ 692:7a9c7b9f6a28

browser_side: use host.default_muc instead of C.DEFAULT_MUC
author souliane <souliane@mailoo.org>
date Thu, 09 Apr 2015 11:37:25 +0200
parents 16079280a39e
children 1d60fa4d25a4
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
685
9877607c719a 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 684
diff changeset
5 # Copyright (C) 2011, 2012, 2013, 2014, 2015 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
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 671
diff changeset
25 from sat_frontends.quick_frontend import quick_menus
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
26 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
27 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
28 from pyjamas.ui.Image import Image
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
29 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
30 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
31 import html_tools
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
32 import base_widget
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
33 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
34
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
35 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
36
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
37
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
38 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
39 """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
40
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
41 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
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
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 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
45 @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
46 @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
47 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
48 """
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
49 # 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
50 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
51 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
52 self.jid = jid_
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
53 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
54 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
55 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
56
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
57 def update(self):
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
58 clist = self.host.contact_list
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
59 alert_html = "<strong>(*)</strong>&nbsp;" if self.jid in clist._alerts else ""
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
60
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":
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
66 clist = self.host.contact_list
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
67 contact_raw = html_tools.html_sanitize(clist.getCache(self.jid, "nick"))
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
68 elif disp == "bare":
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
69 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
70 elif disp == "resource":
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
71 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
72 else:
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
73 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
74 if contact_raw:
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
75 break
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
76 if not contact_raw:
684
e876f493dccc browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents: 676
diff changeset
77 log.error(u"Could not find a contact display for jid {jid} (display: {display})".format(jid=self.jid, display=self.display))
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
78 contact_raw = "UNNAMED"
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
79 contact_html = html_tools.html_sanitize(contact_raw)
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
80
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
81 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
82 '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
83 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
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: 637
diff changeset
85
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
86 class ContactMenuBar(base_widget.WidgetMenuBar):
690
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
87 """WidgetMenuBar displaying the contact's avatar as category."""
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
88
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 def onBrowserEvent(self, event):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
90 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
91 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
92
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 @classmethod
690
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
94 def getCategoryHTML(cls, category):
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
95 """Return the HTML code for displaying contact's avatar.
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
96
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
97 @param category (quick_menus.MenuCategory): ignored
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
98 @return(unicode): HTML to display
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
99 """
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
100 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
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 setUrl(self, url):
690
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
103 """Set the URL of the contact avatar.
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
104
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
105 @param url (unicode): avatar URL
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 687
diff changeset
106 """
691
16079280a39e browser_side: minor fixes for ContactMenuBar and ContactGroupManager
souliane <souliane@mailoo.org>
parents: 690
diff changeset
107 if not self.items: # the menu is empty but we've been asked to set an avatar
16079280a39e browser_side: minor fixes for ContactMenuBar and ContactGroupManager
souliane <souliane@mailoo.org>
parents: 690
diff changeset
108 self.addCategory("dummy")
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
109 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
110
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
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
112 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
113
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 671
diff changeset
114 def __init__(self, host, jid_, style_name=None, display=C.CONTACT_DEFAULT_DISPLAY, plugin_menu_context=None):
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
115 """
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
116 @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
117 @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
118 @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
119 @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
120 contact's label with values in ("jid", "nick", "bare", "resource").
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 671
diff changeset
121 @param plugin_menu_context (iterable): contexts of menus to have (list of C.MENU_* constant)
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
122
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
123 """
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 671
diff changeset
124 self.plugin_menu_context = [] if plugin_menu_context is None else plugin_menu_context
660
267761bf7f08 browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
125 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
126 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
127 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
128 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
129 self.label = ContactLabel(host, self.jid, display=display)
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 671
diff changeset
130 self.avatar = ContactMenuBar(self, host) if plugin_menu_context else Image()
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
131 self.states = 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
132 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
133 self.add(self.label)
684
e876f493dccc browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents: 676
diff changeset
134 self.add(self.states)
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
135 self.update()
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
136 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
137
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
138 def update(self):
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
139 """Update the 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
140
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
141 @param with_bare (bool): if True, ignore the resource and update with bare information.
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
142 """
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
143 self.avatar.setUrl(self.host.getAvatarURL(self.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: 637
diff changeset
144
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
145 self.label.update()
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
146 clist = self.host.contact_list
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
147 show = clist.getCache(self.jid, C.PRESENCE_SHOW)
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
148 if show is None:
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
149 show = C.PRESENCE_UNAVAILABLE
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
150 html_tools.setPresenceStyle(self.label, show)
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
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: 637
diff changeset
152 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
153 try:
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
154 self.parent.onClick(self.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
155 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
156 pass
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 671
diff changeset
157
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 671
diff changeset
158 quick_menus.QuickMenusManager.addDataCollector(C.MENU_JID_CONTEXT, lambda caller, dummy: {'jid': unicode(caller.jid.bare)})