Mercurial > libervia-web
annotate src/browser/sat_browser/contact_widget.py @ 679:a90cc8fc9605
merged branch frontends_multi_profiles
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 18 Mar 2015 16:15:18 +0100 |
parents | 849ffb24d5bf |
children | e876f493dccc |
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 | 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 |
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 | 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 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 |
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 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
|
61 alert_html = "<strong>(*)</strong> " 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
|
62 contact_raw = None |
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
63 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
|
64 if disp == "jid": |
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
65 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
|
66 elif disp == "nick": |
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
67 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
|
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: |
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
77 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
|
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) |
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
|
80 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
|
81 '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
|
82 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
|
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:
637
diff
changeset
|
84 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
|
85 """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
|
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:
637
diff
changeset
|
87 @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
|
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 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
|
90 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
|
91 |
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 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
|
93 """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
|
94 |
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 @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
|
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:
637
diff
changeset
|
97 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
|
98 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
|
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:
637
diff
changeset
|
100 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
101 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
|
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:
637
diff
changeset
|
103 def onBrowserEvent(self, event): |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
104 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
|
105 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
|
106 |
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 @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
|
108 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
|
109 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
|
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 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
|
112 """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
|
113 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
|
114 |
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 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
116 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
|
117 |
676
849ffb24d5bf
browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents:
671
diff
changeset
|
118 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
|
119 """ |
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
|
120 @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
|
121 @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
|
122 @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
|
123 @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
|
124 contact's label with values in ("jid", "nick", "bare", "resource"). |
676
849ffb24d5bf
browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents:
671
diff
changeset
|
125 @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
|
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 """ |
676
849ffb24d5bf
browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents:
671
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 self.label = ContactLabel(host, self.jid, display=display) |
676
849ffb24d5bf
browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents:
671
diff
changeset
|
134 self.avatar = ContactMenuBar(self, host) if plugin_menu_context else Image() |
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
|
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 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
|
145 """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
|
146 |
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 @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
|
148 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
|
149 |
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 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
|
151 """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
|
152 |
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 @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
|
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:
637
diff
changeset
|
155 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
|
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 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
|
158 """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
|
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:
637
diff
changeset
|
160 @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
|
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:
637
diff
changeset
|
162 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
|
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 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
|
165 try: |
660
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 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
|
170 self.setAlert(False) |
676
849ffb24d5bf
browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents:
671
diff
changeset
|
171 |
849ffb24d5bf
browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents:
671
diff
changeset
|
172 quick_menus.QuickMenusManager.addDataCollector(C.MENU_JID_CONTEXT, lambda caller, dummy: {'jid': unicode(caller.jid.bare)}) |