Mercurial > libervia-web
annotate src/browser/sat_browser/contact.py @ 512:750db9ff8525
server side: launching script improvments:
- no more difference between installed version and source version: libervia is a deamon by defaut, "fg" must be used to launch it foreground
- fixed bad constants module imported in python part of libervia.sh
- fixed stdout encoding in python part of libervia.sh
- APP_NAME and APP_NAME_FILE use the constants module values
- DATA_DIR variable moved to PLUGIN_OPTIONS
- (constants) ASCII_APP_NAME renamed to APP_NAME_FILE to be consistent with SàT backend.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 24 Aug 2014 18:43:45 +0200 |
parents | db3436c85fb1 |
children | 3d8e8f693576 |
rev | line source |
---|---|
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
340 | 5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org> |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
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:
323
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:
323
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:
323
diff
changeset
|
10 # (at your option) any later version. |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
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:
323
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:
323
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:
323
diff
changeset
|
15 # GNU Affero General Public License for more details. |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
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:
323
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
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:
413
diff
changeset
|
21 from sat.core.log import getLogger |
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
22 log = getLogger(__name__) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from pyjamas.ui.SimplePanel import SimplePanel |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
24 from pyjamas.ui.ScrollPanel import ScrollPanel |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from pyjamas.ui.VerticalPanel import VerticalPanel |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
27 from pyjamas.ui.ClickListener import ClickHandler |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from pyjamas.ui.Label import Label |
62 | 29 from pyjamas.ui.HTML import HTML |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
30 from pyjamas.ui.Image import Image |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from pyjamas import Window |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from pyjamas import DOM |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
439
diff
changeset
|
33 from __pyjamas__ import doc |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
35 from constants import Const as C |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
439
diff
changeset
|
36 from jid import JID |
467 | 37 import base_widget |
38 import panels | |
39 import html_tools | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
41 |
510
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
42 def buildPresenceStyle(presence, base_style=None): |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
43 """Return the CSS classname to be used for displaying the given presence information. |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
44 @param presence (str): presence is a value in ('', 'chat', 'away', 'dnd', 'xa') |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
45 @param base_style (str): base classname |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
46 @return: str |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
47 """ |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
48 if not base_style: |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
49 base_style = "contactLabel" |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
50 return '%s-%s' % (base_style, presence or 'connected') |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
51 |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
52 |
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
53 def setPresenceStyle(widget, presence, base_style=None): |
370
30d03d9f07e4
browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
54 """ |
30d03d9f07e4
browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
55 Set the CSS style of a contact's element according to its presence. |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
56 |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
57 @param widget (Widget): the UI element of the contact |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
58 @param presence (str): a value in ("", "chat", "away", "dnd", "xa"). |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
59 @param base_style (str): the base name of the style to apply |
370
30d03d9f07e4
browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
60 """ |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
61 if not hasattr(widget, 'presence_style'): |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
62 widget.presence_style = None |
510
db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
63 style = buildPresenceStyle(presence, base_style) |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
64 if style == widget.presence_style: |
370
30d03d9f07e4
browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
65 return |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
66 if widget.presence_style is not None: |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
67 widget.removeStyleName(widget.presence_style) |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
68 widget.addStyleName(style) |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
69 widget.presence_style = style |
370
30d03d9f07e4
browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
70 |
30d03d9f07e4
browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
71 |
467 | 72 class GroupLabel(base_widget.DragLabel, Label, ClickHandler): |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
73 def __init__(self, host, group): |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
74 self.group = group |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
75 self.host = host |
451 | 76 Label.__init__(self, group) # , Element=DOM.createElement('div') |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
77 self.setStyleName('group') |
467 | 78 base_widget.DragLabel.__init__(self, group, "GROUP") |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
79 ClickHandler.__init__(self) |
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
80 self.addClickListener(self) |
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
81 |
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
82 def onClick(self, sender): |
467 | 83 self.host.getOrCreateLiberviaWidget(panels.MicroblogPanel, self.group) |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
84 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
85 |
485
5911f71acc80
browser side: move contacts list's avatar from right to top
souliane <souliane@mailoo.org>
parents:
480
diff
changeset
|
86 class ContactLabel(HTML): |
5911f71acc80
browser side: move contacts list's avatar from right to top
souliane <souliane@mailoo.org>
parents:
480
diff
changeset
|
87 def __init__(self, jid, name=None): |
62 | 88 HTML.__init__(self) |
89 self.name = name or jid | |
90 self.waiting = False | |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
91 self.refresh() |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
92 self.setStyleName('contactLabel') |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
94 def refresh(self): |
62 | 95 if self.waiting: |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
96 wait_html = "<b>(*)</b> " |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
97 self.setHTML("%(wait)s%(name)s" % {'wait': wait_html, |
467 | 98 'name': html_tools.html_sanitize(self.name)}) |
62 | 99 |
100 def setMessageWaiting(self, waiting): | |
101 """Show a visual indicator if message are waiting | |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
102 |
62 | 103 @param waiting: True if message are waiting""" |
104 self.waiting = waiting | |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
105 self.refresh() |
62 | 106 |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
107 |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
108 class ContactMenuBar(base_widget.WidgetMenuBar): |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
109 |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
110 def onBrowserEvent(self, event): |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
111 base_widget.WidgetMenuBar.onBrowserEvent(self, event) |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
112 event.stopPropagation() # prevent opening the chat dialog |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
113 |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
114 |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
115 class ContactBox(VerticalPanel, ClickHandler, base_widget.DragLabel): |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
116 |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
117 def __init__(self, host, jid, name=None, click_listener=None, handle_menu=None): |
485
5911f71acc80
browser side: move contacts list's avatar from right to top
souliane <souliane@mailoo.org>
parents:
480
diff
changeset
|
118 VerticalPanel.__init__(self, StyleName='contactBox', VerticalAlignment='middle') |
5911f71acc80
browser side: move contacts list's avatar from right to top
souliane <souliane@mailoo.org>
parents:
480
diff
changeset
|
119 base_widget.DragLabel.__init__(self, jid, "CONTACT") |
5911f71acc80
browser side: move contacts list's avatar from right to top
souliane <souliane@mailoo.org>
parents:
480
diff
changeset
|
120 self.host = host |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
121 self.jid = jid |
485
5911f71acc80
browser side: move contacts list's avatar from right to top
souliane <souliane@mailoo.org>
parents:
480
diff
changeset
|
122 self.label = ContactLabel(jid, name) |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
123 self.avatar = Image() |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
124 self.updateAvatar(host.getAvatar(jid)) |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
125 extra = HorizontalPanel() |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
126 extra.add(self.avatar) |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
127 self.add(extra) |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
128 self.add(self.label) |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
129 if click_listener: |
485
5911f71acc80
browser side: move contacts list's avatar from right to top
souliane <souliane@mailoo.org>
parents:
480
diff
changeset
|
130 ClickHandler.__init__(self) |
5911f71acc80
browser side: move contacts list's avatar from right to top
souliane <souliane@mailoo.org>
parents:
480
diff
changeset
|
131 self.addClickListener(self) |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
132 self.click_listener = click_listener |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
133 |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
134 if handle_menu: |
498
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
495
diff
changeset
|
135 extra.add(ContactMenuBar(self, host)) |
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
495
diff
changeset
|
136 |
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
495
diff
changeset
|
137 def addMenus(self, menu_bar): |
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
495
diff
changeset
|
138 menu_bar.addCachedMenus(C.MENU_ROSTER_JID_CONTEXT, {'jid': self.jid}) |
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
495
diff
changeset
|
139 menu_bar.addCachedMenus(C.MENU_JID_CONTEXT, {'jid': self.jid}) |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
140 |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
141 def setMessageWaiting(self, waiting): |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
142 """Show a visual indicator if message are waiting |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
143 |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
144 @param waiting: True if message are waiting""" |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
145 self.label.setMessageWaiting(waiting) |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
146 |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
147 def updateAvatar(self, url): |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
148 """Update the avatar |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
149 |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
150 @param url (str): image url |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
151 """ |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
152 self.avatar.setVisible(url != C.DEFAULT_AVATAR) |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
153 self.avatar.setUrl(url) |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
154 |
485
5911f71acc80
browser side: move contacts list's avatar from right to top
souliane <souliane@mailoo.org>
parents:
480
diff
changeset
|
155 def onClick(self, sender): |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
156 self.click_listener(self.jid) |
485
5911f71acc80
browser side: move contacts list's avatar from right to top
souliane <souliane@mailoo.org>
parents:
480
diff
changeset
|
157 |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
158 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 class GroupList(VerticalPanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 def __init__(self, parent): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 VerticalPanel.__init__(self) |
74
3df602cf700a
browser side: groups design
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
66
diff
changeset
|
163 self.setStyleName('groupList') |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 self._parent = parent |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 def add(self, group): |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
167 _item = GroupLabel(self._parent.host, group) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 _item.addMouseListener(self._parent) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
170 index = 0 |
459
36f27d1e64b2
browser_side: avoid warning "list comprehension redefines 'group' from line XXX"
souliane <souliane@mailoo.org>
parents:
455
diff
changeset
|
171 for group_ in [child.group for child in self.getChildren()]: |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
172 if group_ > group: |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
173 break |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
174 index += 1 |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
175 VerticalPanel.insert(self, _item, index) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
176 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
177 def remove(self, group): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
178 for wid in self: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
179 if isinstance(wid, GroupLabel) and wid.group == group: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
180 VerticalPanel.remove(self, wid) |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
181 |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
182 |
252
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
183 class GenericContactList(VerticalPanel): |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
184 """Class that can be used to represent a contact list, but not necessarily |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
185 the one that is displayed on the left side. Special features like popup menu |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
186 panel or changing the contact states must be done in a sub-class.""" |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
188 def __init__(self, host, handle_click=False, handle_menu=False): |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 VerticalPanel.__init__(self) |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
190 self.host = host |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
191 self.contacts = [] |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
192 self.click_listener = None |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
193 self.handle_menu = handle_menu |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
194 |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
195 if handle_click: |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
196 def cb(contact_jid): |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
197 self.host.getOrCreateLiberviaWidget(panels.ChatPanel, contact_jid) |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
198 self.click_listener = cb |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
199 |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
200 def add(self, jid, name=None): |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
201 """Add a contact to the list. |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
202 |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
203 @param jid (str): JID of the contact |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
204 @param name (str): optional name of the contact |
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
205 """ |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
206 if jid in self.contacts: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
207 return |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
208 index = 0 |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
209 for contact_ in self.contacts: |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
210 if contact_ > jid: |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
211 break |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
212 index += 1 |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
252
diff
changeset
|
213 self.contacts.insert(index, jid) |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
214 box = ContactBox(self.host, jid, name, self.click_listener, self.handle_menu) |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
215 VerticalPanel.insert(self, box, index) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
216 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
217 def remove(self, jid): |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
218 box = self.getContactBox(jid) |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
219 if not box: |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
220 return |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
221 VerticalPanel.remove(self, box) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
222 self.contacts.remove(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
223 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
224 def isContactPresent(self, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
225 """Return True if a contact is present in the panel""" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
226 return contact_jid in self.contacts |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
227 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
228 def getContacts(self): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
229 return self.contacts |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
230 |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
231 def getContactBox(self, contact_jid): |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
232 """get contactList widget of a contact |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
233 @return: ContactBox instance if present, else None""" |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
234 for wid in self: |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
235 if isinstance(wid, ContactBox) and wid.jid == contact_jid: |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
236 return wid |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
237 return None |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
239 def updateAvatar(self, jid_s, url): |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
240 """Update the avatar of the given contact |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
241 |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
242 @param jid_s (str): contact jid |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
243 @param url (str): image url |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
244 """ |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
245 try: |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
246 self.getContactBox(jid_s).updateAvatar(url) |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
247 except TypeError: |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
248 pass |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
249 |
252
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
250 |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
251 class ContactList(GenericContactList): |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
252 """The contact list that is displayed on the left side.""" |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
253 |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
254 def __init__(self, host): |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
255 GenericContactList.__init__(self, host, handle_click=True, handle_menu=True) |
252
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
256 |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
257 def contextMenuHide(self, sender, key): |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
258 """Return True if the item for that sender should be hidden.""" |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
259 # TODO: enable the blogs of users that are on another server |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
260 return JID(sender.jid).domain != self.host._defaultDomain |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
261 |
455
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
262 def add(self, jid_s, name=None): |
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
263 """Add a contact |
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
264 |
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
265 @param jid_s (str): JID as unicode |
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
266 @param name (str): nickname |
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
267 """ |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
485
diff
changeset
|
268 GenericContactList.add(self, jid_s, name) |
252
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
269 |
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
270 def setState(self, jid, type_, state): |
47
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
271 """Change the appearance of the contact, according to the state |
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
272 @param jid: jid which need to change state |
252
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
273 @param type_: one of availability, messageWaiting |
62 | 274 @param state: |
275 - for messageWaiting type: | |
276 True if message are waiting | |
277 - for availability type: | |
278 'unavailable' if not connected, else presence like RFC6121 #4.7.2.1""" | |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
279 contact_box = self.getContactBox(jid) |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
280 if contact_box: |
252
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
281 if type_ == 'availability': |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
282 setPresenceStyle(contact_box.label, state) |
252
b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents:
242
diff
changeset
|
283 elif type_ == 'messageWaiting': |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
284 contact_box.setMessageWaiting(state) |
47
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
285 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
286 |
467 | 287 class ContactTitleLabel(base_widget.DragLabel, Label, ClickHandler): |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
288 def __init__(self, host, text): |
451 | 289 Label.__init__(self, text) # , Element=DOM.createElement('div') |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
290 self.host = host |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
291 self.setStyleName('contactTitle') |
467 | 292 base_widget.DragLabel.__init__(self, text, "CONTACT_TITLE") |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
293 ClickHandler.__init__(self) |
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
294 self.addClickListener(self) |
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
295 |
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
296 def onClick(self, sender): |
467 | 297 self.host.getOrCreateLiberviaWidget(panels.MicroblogPanel, None) |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
298 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
299 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 class ContactPanel(SimplePanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 """Manage the contacts and groups""" |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
302 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 def __init__(self, host): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 SimplePanel.__init__(self) |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
305 |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
306 self.scroll_panel = ScrollPanel() |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
307 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 self.host = host |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
309 self.groups = {} |
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
310 self.connected = {} # jid connected as key and their status |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 self.vPanel = VerticalPanel() |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
313 _title = ContactTitleLabel(host, 'Contacts') |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
314 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer") |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
316 self._contact_list = ContactList(host) |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
317 self._contact_list.setStyleName('contactList') |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 self._groupList = GroupList(self) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 self._groupList.setStyleName('groupList') |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
320 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 self.vPanel.add(_title) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 self.vPanel.add(self._groupList) |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
323 self.vPanel.add(self._contact_list) |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
324 self.scroll_panel.add(self.vPanel) |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
325 self.add(self.scroll_panel) |
479
c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
326 self.setStyleName('contactPanel') |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
327 Window.addWindowResizeListener(self) |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
328 |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
329 def onWindowResized(self, width, height): |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
330 contact_panel_elt = self.getElement() |
467 | 331 classname = 'widgetsPanel' if isinstance(self.getParent().getParent(), panels.UniBoxPanel) else'gwt-TabBar' |
290
3216c8d5432b
browser_side: set the ideal height for the contact panel size when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
332 _elts = doc().getElementsByClassName(classname) |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
333 if not _elts.length: |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
334 log.error("no element of class %s found, it should exist !" % classname) |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
335 tab_bar_h = height |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
336 else: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
337 tab_bar_h = DOM.getAbsoluteTop(_elts.item(0)) or height # getAbsoluteTop can be 0 if tabBar is hidden |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
338 |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
339 ideal_height = tab_bar_h - DOM.getAbsoluteTop(contact_panel_elt) - 5 |
290
3216c8d5432b
browser_side: set the ideal height for the contact panel size when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
340 self.scroll_panel.setHeight("%s%s" % (ideal_height, "px")) |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
341 |
455
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
342 def updateContact(self, jid_s, attributes, groups): |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
343 """Add a contact to the panel if it doesn't exist, update it else |
455
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
344 @param jid_s: jid userhost as unicode |
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
345 @param attributes: cf SàT Bridge API's newContact |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 @param groups: list of groups""" |
455
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
347 _current_groups = self.getContactGroups(jid_s) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
348 _new_groups = set(groups) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
349 _key = "@%s: " |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
350 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
351 for group in _current_groups.difference(_new_groups): |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
352 # We remove the contact from the groups where he isn't anymore |
455
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
353 self.groups[group].remove(jid_s) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
354 if not self.groups[group]: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
355 # The group is now empty, we must remove it |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
356 del self.groups[group] |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
357 self._groupList.remove(group) |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
304
diff
changeset
|
358 if self.host.uni_box: |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
304
diff
changeset
|
359 self.host.uni_box.removeKey(_key % group) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
360 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
361 for group in _new_groups.difference(_current_groups): |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
362 # We add the contact to the groups he joined |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
363 if not group in self.groups.keys(): |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 self.groups[group] = set() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 self._groupList.add(group) |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
304
diff
changeset
|
366 if self.host.uni_box: |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
304
diff
changeset
|
367 self.host.uni_box.addKey(_key % group) |
455
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
368 self.groups[group].add(jid_s) |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
369 |
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
370 # We add the contact to contact list, it will check if contact already exists |
455
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
371 self._contact_list.add(jid_s) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
373 def removeContact(self, jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
374 """Remove contacts from groups where he is and contact list""" |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
375 self.updateContact(jid, {}, []) # we remove contact from every group |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
376 self._contact_list.remove(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
377 |
28 | 378 def setConnected(self, jid, resource, availability, priority, statuses): |
272
0cb9869b42b6
browser_side: bug fix for RoomAndContactsChooser (do not display the MUCs in the list)
souliane <souliane@mailoo.org>
parents:
271
diff
changeset
|
379 """Set connection status |
0cb9869b42b6
browser_side: bug fix for RoomAndContactsChooser (do not display the MUCs in the list)
souliane <souliane@mailoo.org>
parents:
271
diff
changeset
|
380 @param jid: JID userhost as unicode |
0cb9869b42b6
browser_side: bug fix for RoomAndContactsChooser (do not display the MUCs in the list)
souliane <souliane@mailoo.org>
parents:
271
diff
changeset
|
381 """ |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
382 if availability == 'unavailable': |
304
2ab513a47e3b
browser_side: fix presence/status update (do not share between different resources)
souliane <souliane@mailoo.org>
parents:
290
diff
changeset
|
383 if jid in self.connected: |
2ab513a47e3b
browser_side: fix presence/status update (do not share between different resources)
souliane <souliane@mailoo.org>
parents:
290
diff
changeset
|
384 if resource in self.connected[jid]: |
28 | 385 del self.connected[jid][resource] |
386 if not self.connected[jid]: | |
387 del self.connected[jid] | |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
388 else: |
304
2ab513a47e3b
browser_side: fix presence/status update (do not share between different resources)
souliane <souliane@mailoo.org>
parents:
290
diff
changeset
|
389 if not jid in self.connected: |
28 | 390 self.connected[jid] = {} |
391 self.connected[jid][resource] = (availability, priority, statuses) | |
413
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
392 |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
393 # check if the contact is connected with another resource, use the one with highest priority |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
394 if jid in self.connected: |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
395 max_resource = max_priority = None |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
396 for tmp_resource in self.connected[jid]: |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
397 if max_priority is None or self.connected[jid][tmp_resource][1] >= max_priority: |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
398 max_resource = tmp_resource |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
399 max_priority = self.connected[jid][tmp_resource][1] |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
400 if availability == "unavailable": # do not check the priority here, because 'unavailable' has a dummy one |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
401 priority = max_priority |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
402 availability = self.connected[jid][max_resource][0] |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
403 if jid not in self.connected or priority >= max_priority: |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
404 # case 1: jid not in self.connected means all resources are disconnected, update with 'unavailable' |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
405 # case 2: update (or confirm) with the values of the resource which takes precedence |
7a8991cda2fa
browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents:
372
diff
changeset
|
406 self._contact_list.setState(jid, "availability", availability) |
62 | 407 |
271
d868181d0649
browser_side: update contacts in "group and contact chooser" when the a user connect/disconnect
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
408 # update the connected contacts chooser live |
d868181d0649
browser_side: update contacts in "group and contact chooser" when the a user connect/disconnect
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
409 if hasattr(self.host, "room_contacts_chooser") and self.host.room_contacts_chooser is not None: |
d868181d0649
browser_side: update contacts in "group and contact chooser" when the a user connect/disconnect
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
410 self.host.room_contacts_chooser.resetContacts() |
d868181d0649
browser_side: update contacts in "group and contact chooser" when the a user connect/disconnect
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
411 |
62 | 412 def setContactMessageWaiting(self, jid, waiting): |
413 """Show an visual indicator that contact has send a message | |
414 @param jid: jid of the contact | |
415 @param waiting: True if message are waiting""" | |
416 self._contact_list.setState(jid, "messageWaiting", waiting) | |
417 | |
272
0cb9869b42b6
browser_side: bug fix for RoomAndContactsChooser (do not display the MUCs in the list)
souliane <souliane@mailoo.org>
parents:
271
diff
changeset
|
418 def getConnected(self, filter_muc=False): |
0cb9869b42b6
browser_side: bug fix for RoomAndContactsChooser (do not display the MUCs in the list)
souliane <souliane@mailoo.org>
parents:
271
diff
changeset
|
419 """return a list of all jid (bare jid) connected |
0cb9869b42b6
browser_side: bug fix for RoomAndContactsChooser (do not display the MUCs in the list)
souliane <souliane@mailoo.org>
parents:
271
diff
changeset
|
420 @param filter_muc: if True, remove the groups from the list |
0cb9869b42b6
browser_side: bug fix for RoomAndContactsChooser (do not display the MUCs in the list)
souliane <souliane@mailoo.org>
parents:
271
diff
changeset
|
421 """ |
265
56a307f08ffe
browser_side: sort the the result of ContactList.getConnected()
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
422 contacts = self.connected.keys() |
56a307f08ffe
browser_side: sort the the result of ContactList.getConnected()
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
423 contacts.sort() |
272
0cb9869b42b6
browser_side: bug fix for RoomAndContactsChooser (do not display the MUCs in the list)
souliane <souliane@mailoo.org>
parents:
271
diff
changeset
|
424 return contacts if not filter_muc else list(set(contacts).intersection(set(self.getContacts()))) |
28 | 425 |
455
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
426 def getContactGroups(self, contact_jid_s): |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
427 """Get groups where contact is |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
428 @param group: string of single group, or list of string |
455
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
429 @param contact_jid_s: jid to test, as unicode |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
430 """ |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
431 result = set() |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
432 for group in self.groups: |
455
05e98b8d9f02
browser side: display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
451
diff
changeset
|
433 if self.isContactInGroup(group, contact_jid_s): |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
434 result.add(group) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
435 return result |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
436 |
13 | 437 def isContactInGroup(self, group, contact_jid): |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
438 """Test if the contact_jid is in the group |
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
439 @param group: string of single group, or list of string |
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
440 @param contact_jid: jid to test |
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
441 @return: True if contact_jid is in on of the groups""" |
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
442 if group in self.groups and contact_jid in self.groups[group]: |
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
443 return True |
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
444 return False |
13 | 445 |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
446 def isContactInRoster(self, contact_jid): |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
447 """Test if the contact is in our roster list""" |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
448 for contact_box in self._contact_list: |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
449 if contact_jid == contact_box.jid: |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
450 return True |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
451 return False |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
452 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
453 def getContacts(self): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
454 return self._contact_list.getContacts() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
455 |
21
77c2e48efa29
browser side: a warning message now show who will receive the message entered in UniBox, with a color depending on how many people will be able to see it
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
456 def getGroups(self): |
77c2e48efa29
browser side: a warning message now show who will receive the message entered in UniBox, with a color depending on how many people will be able to see it
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
457 return self.groups.keys() |
77c2e48efa29
browser side: a warning message now show who will receive the message entered in UniBox, with a color depending on how many people will be able to see it
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
458 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 def onMouseMove(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
460 pass |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
461 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
462 def onMouseDown(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
465 def onMouseUp(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 def onMouseEnter(self, sender): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 if isinstance(sender, GroupLabel): |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
470 for contact in self._contact_list: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
471 if contact.jid in self.groups[sender.group]: |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
472 contact.label.addStyleName("selected") |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
200
diff
changeset
|
473 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 def onMouseLeave(self, sender): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 if isinstance(sender, GroupLabel): |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
476 for contact in self._contact_list: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 if contact.jid in self.groups[sender.group]: |
480
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
478 contact.label.removeStyleName("selected") |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
479 |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
480 def updateAvatar(self, jid_s, url): |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
481 """Update the avatar of the given contact |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
482 |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
483 @param jid_s (str): contact jid |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
484 @param url (str): image url |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
485 """ |
50b286866739
browser side: display avatars in the contact panel
souliane <souliane@mailoo.org>
parents:
479
diff
changeset
|
486 self._contact_list.updateAvatar(jid_s, url) |