annotate src/browser/contact.py @ 451:1a0cec9b0f1e

better PEP-8 compliance
author souliane <souliane@mailoo.org>
date Tue, 20 May 2014 10:54:03 +0200
parents 981ed669d3b3
children 05e98b8d9f02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ce5b33f499c5 dates update
Goffi <goffi@goffi.org>
parents: 339
diff changeset
5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org>
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
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
26 from pyjamas.ui.ClickListener import ClickHandler
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.Label import Label
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
28 from pyjamas.ui.HTML import HTML
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from pyjamas import Window
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
30 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
31 from __pyjamas__ import doc
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
32
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 jid import JID
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 439
diff changeset
34
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 439
diff changeset
35 from base_panels import PopupMenuPanel
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 439
diff changeset
36 from base_widget import DragLabel
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 439
diff changeset
37 from panels import ChatPanel, MicroblogPanel, WebPanel, UniBoxPanel
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 439
diff changeset
38 from html_tools import html_sanitize
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
39
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
40
370
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
41 def setPresenceStyle(element, presence, base_style="contact"):
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
42 """
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
43 Set the CSS style of a contact's element according to its presence.
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
44 @param item: the UI element of the contact
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
45 @param presence: a value in ("", "chat", "away", "dnd", "xa").
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
46 @param base_style: the base name of the style to apply
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
47 """
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
48 if not hasattr(element, 'presence_style'):
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
49 element.presence_style = None
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
50 style = '%s-%s' % (base_style, presence or 'connected')
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
51 if style == element.presence_style:
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
52 return
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
53 if element.presence_style is not None:
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
54 element.removeStyleName(element.presence_style)
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
55 element.addStyleName(style)
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
56 element.presence_style = style
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
57
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
58
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
59 class GroupLabel(DragLabel, Label, ClickHandler):
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
60 def __init__(self, host, group):
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
61 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
62 self.host = host
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
63 Label.__init__(self, group) # , Element=DOM.createElement('div')
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
64 self.setStyleName('group')
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
65 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
66 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
67 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
68
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
69 def onClick(self, sender):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
70 self.host.getOrCreateLiberviaWidget(MicroblogPanel, self.group)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
71
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
72
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 class ContactLabel(DragLabel, HTML, ClickHandler):
262
30c01671e338 browser_side: small changes for contact list and "add group" panel:
souliane <souliane@mailoo.org>
parents: 255
diff changeset
74 def __init__(self, host, jid, name=None, handleClick=True):
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
75 HTML.__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
76 self.host = host
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
77 self.name = name or jid
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
78 self.waiting = False
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
79 self.jid = jid
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
80 self._fill()
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
81 self.setStyleName('contact')
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 17
diff changeset
82 DragLabel.__init__(self, jid, "CONTACT")
262
30c01671e338 browser_side: small changes for contact list and "add group" panel:
souliane <souliane@mailoo.org>
parents: 255
diff changeset
83 if handleClick:
30c01671e338 browser_side: small changes for contact list and "add group" panel:
souliane <souliane@mailoo.org>
parents: 255
diff changeset
84 ClickHandler.__init__(self)
30c01671e338 browser_side: small changes for contact list and "add group" panel:
souliane <souliane@mailoo.org>
parents: 255
diff changeset
85 self.addClickListener(self)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
86
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
87 def _fill(self):
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
88 if self.waiting:
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
89 _wait_html = "<b>(*)</b>&nbsp;"
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
90 self.setHTML("%(wait)s%(name)s" % {'wait': _wait_html,
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
91 'name': html_sanitize(self.name)})
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
92
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
93 def setMessageWaiting(self, waiting):
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
94 """Show a visual indicator if message are waiting
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
95 @param waiting: True if message are waiting"""
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
96 self.waiting = waiting
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
97 self._fill()
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
98
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
99 def onClick(self, sender):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
100 self.host.getOrCreateLiberviaWidget(ChatPanel, self.jid)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
101
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
102
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
103 class GroupList(VerticalPanel):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
104
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
105 def __init__(self, parent):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
106 VerticalPanel.__init__(self)
74
3df602cf700a browser side: groups design
Adrien Vigneron <adrienvigneron@mailoo.org>
parents: 66
diff changeset
107 self.setStyleName('groupList')
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self._parent = parent
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
109
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
110 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
111 _item = GroupLabel(self._parent.host, group)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
112 _item.addMouseListener(self._parent)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
113 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
114 index = 0
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
115 for group_ in [group.group for group in self.getChildren()]:
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
116 if group_ > group:
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
117 break
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
118 index += 1
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
119 VerticalPanel.insert(self, _item, index)
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
120
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
121 def remove(self, group):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
122 for wid in self:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
123 if isinstance(wid, GroupLabel) and wid.group == group:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
124 VerticalPanel.remove(self, wid)
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
125
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
126
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
127 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
128 """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
129 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
130 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
131
262
30c01671e338 browser_side: small changes for contact list and "add group" panel:
souliane <souliane@mailoo.org>
parents: 255
diff changeset
132 def __init__(self, host, handleClick=False):
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
133 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
134 self.host = host
255
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
135 self.contacts = []
262
30c01671e338 browser_side: small changes for contact list and "add group" panel:
souliane <souliane@mailoo.org>
parents: 255
diff changeset
136 self.handleClick = handleClick
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
137
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
138 def add(self, jid, name=None, item_cb=None):
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
139 if jid in self.contacts:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
140 return
255
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
141 index = 0
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
142 for contact_ in self.contacts:
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
143 if contact_ > jid:
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
144 break
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
145 index += 1
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 252
diff changeset
146 self.contacts.insert(index, jid)
262
30c01671e338 browser_side: small changes for contact list and "add group" panel:
souliane <souliane@mailoo.org>
parents: 255
diff changeset
147 _item = ContactLabel(self.host, jid, name, handleClick=self.handleClick)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
148 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
149 VerticalPanel.insert(self, _item, index)
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
150 if item_cb is not None:
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
151 item_cb(_item)
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
152
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
153 def remove(self, jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
154 wid = self.getContactLabel(jid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
155 if not wid:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
156 return
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
157 VerticalPanel.remove(self, wid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
158 self.contacts.remove(jid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
159
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
160 def isContactPresent(self, contact_jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
161 """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
162 return contact_jid in self.contacts
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
163
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
164 def getContacts(self):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
165 return self.contacts
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
166
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
167 def getContactLabel(self, contact_jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
168 """get contactList widget of a contact
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
169 @return: ContactLabel item if present, else None"""
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
170 for wid in self:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
171 if isinstance(wid, ContactLabel) and wid.jid == contact_jid:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
172 return wid
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
173 return None
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
174
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
175
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
176 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
177 """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
178
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
179 def __init__(self, host):
262
30c01671e338 browser_side: small changes for contact list and "add group" panel:
souliane <souliane@mailoo.org>
parents: 255
diff changeset
180 GenericContactList.__init__(self, host, handleClick=True)
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
181 self.menu_entries = {"blog": {"title": "Public blog..."}}
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
182 self.context_menu = PopupMenuPanel(entries=self.menu_entries,
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
183 hide=self.contextMenuHide,
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
184 callback=self.contextMenuCallback,
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 272
diff changeset
185 vertical=False, style={"selected": "menu-selected"})
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
186
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
187 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
188 """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
189 # 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
190 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
191
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
192 def contextMenuCallback(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
193 if key == "blog":
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
194 # TODO: use the bare when all blogs can be retrieved
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
195 node = JID(sender.jid).node
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
196 web_panel = WebPanel(self.host, "/blog/%s" % node)
267
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 265
diff changeset
197 self.host.addTab("%s's blog" % node, web_panel)
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
198 else:
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
199 sender.onClick(sender)
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
200
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
201 def add(self, jid, name=None):
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
202 def item_cb(item):
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
203 self.context_menu.registerRightClickSender(item)
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
204 GenericContactList.add(self, jid, name, item_cb)
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
205
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
206 def setState(self, jid, type_, state):
47
7cabe3c1a5f2 browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents: 33
diff changeset
207 """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
208 @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
209 @param type_: one of availability, messageWaiting
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
210 @param state:
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
211 - for messageWaiting type:
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
212 True if message are waiting
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
213 - for availability type:
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
214 'unavailable' if not connected, else presence like RFC6121 #4.7.2.1"""
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
215 _item = self.getContactLabel(jid)
47
7cabe3c1a5f2 browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents: 33
diff changeset
216 if _item:
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
217 if type_ == 'availability':
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 272
diff changeset
218 setPresenceStyle(_item, state)
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
219 elif type_ == 'messageWaiting':
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
220 _item.setMessageWaiting(state)
47
7cabe3c1a5f2 browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents: 33
diff changeset
221
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
222
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
223 class ContactTitleLabel(DragLabel, Label, ClickHandler):
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
224 def __init__(self, host, text):
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
225 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
226 self.host = host
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
227 self.setStyleName('contactTitle')
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 17
diff changeset
228 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
229 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
230 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
231
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
232 def onClick(self, sender):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
233 self.host.getOrCreateLiberviaWidget(MicroblogPanel, None)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
234
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
235
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
236 class ContactPanel(SimplePanel):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
237 """Manage the contacts and groups"""
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
238
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
239 def __init__(self, host):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
240 SimplePanel.__init__(self)
187
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
241
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
242 self.scroll_panel = ScrollPanel()
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
243
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
244 self.host = host
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
245 self.groups = {}
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
246 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
247
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
248 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
249 _title = ContactTitleLabel(host, 'Contacts')
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
250 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer")
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
251
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
252 self._contact_list = ContactList(host)
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
253 self._contact_list.setStyleName('contactList')
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
254 self._groupList = GroupList(self)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
255 self._groupList.setStyleName('groupList')
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
256
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
257 self.vPanel.add(_title)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
258 self.vPanel.add(self._groupList)
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
259 self.vPanel.add(self._contact_list)
187
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
260 self.scroll_panel.add(self.vPanel)
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
261 self.add(self.scroll_panel)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
262 self.setStyleName('contactBox')
187
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
263 Window.addWindowResizeListener(self)
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
264
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
265 def onWindowResized(self, width, height):
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
266 contact_panel_elt = self.getElement()
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
267 classname = 'widgetsPanel' if isinstance(self.getParent().getParent(), UniBoxPanel) else'gwt-TabBar'
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
268 _elts = doc().getElementsByClassName(classname)
187
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
269 if not _elts.length:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 413
diff changeset
270 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
271 tab_bar_h = height
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
272 else:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
273 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
274
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
275 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
276 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
277
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
278 def updateContact(self, jid, attributes, groups):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
279 """Add a contact to the panel if it doesn't exist, update it else
272
0cb9869b42b6 browser_side: bug fix for RoomAndContactsChooser (do not display the MUCs in the list)
souliane <souliane@mailoo.org>
parents: 271
diff changeset
280 @param jid: jid userhost as unicode
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
281 @attributes: cf SàT Bridge API's newContact
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
282 @param groups: list of groups"""
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
283 _current_groups = self.getContactGroups(jid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
284 _new_groups = set(groups)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
285 _key = "@%s: "
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
286
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
287 for group in _current_groups.difference(_new_groups):
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
288 # We remove the contact from the groups where he isn't anymore
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
289 self.groups[group].remove(jid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
290 if not self.groups[group]:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
291 # 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
292 del self.groups[group]
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
293 self._groupList.remove(group)
309
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 304
diff changeset
294 if self.host.uni_box:
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 304
diff changeset
295 self.host.uni_box.removeKey(_key % group)
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
296
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
297 for group in _new_groups.difference(_current_groups):
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
298 # 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
299 if not group in self.groups.keys():
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
300 self.groups[group] = set()
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
301 self._groupList.add(group)
309
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 304
diff changeset
302 if self.host.uni_box:
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 304
diff changeset
303 self.host.uni_box.addKey(_key % group)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
304 self.groups[group].add(jid)
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
305
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
306 # We add the contact to contact list, it will check if contact already exists
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
307 self._contact_list.add(jid)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
308
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
309 def removeContact(self, jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
310 """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
311 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
312 self._contact_list.remove(jid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
313
28
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
314 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
315 """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
316 @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
317 """
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
318 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
319 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
320 if resource in self.connected[jid]:
28
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
321 del self.connected[jid][resource]
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
322 if not self.connected[jid]:
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
323 del self.connected[jid]
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
324 else:
304
2ab513a47e3b browser_side: fix presence/status update (do not share between different resources)
souliane <souliane@mailoo.org>
parents: 290
diff changeset
325 if not jid in self.connected:
28
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
326 self.connected[jid] = {}
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
327 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
328
7a8991cda2fa browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents: 372
diff changeset
329 # 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
330 if jid in self.connected:
7a8991cda2fa browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents: 372
diff changeset
331 max_resource = max_priority = None
7a8991cda2fa browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents: 372
diff changeset
332 for tmp_resource in self.connected[jid]:
7a8991cda2fa browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents: 372
diff changeset
333 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
334 max_resource = tmp_resource
7a8991cda2fa browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents: 372
diff changeset
335 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
336 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
337 priority = max_priority
7a8991cda2fa browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents: 372
diff changeset
338 availability = self.connected[jid][max_resource][0]
7a8991cda2fa browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents: 372
diff changeset
339 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
340 # 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
341 # 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
342 self._contact_list.setState(jid, "availability", availability)
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
343
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
344 # 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
345 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
346 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
347
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
348 def setContactMessageWaiting(self, jid, waiting):
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
349 """Show an visual indicator that contact has send a message
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
350 @param jid: jid of the contact
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
351 @param waiting: True if message are waiting"""
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
352 self._contact_list.setState(jid, "messageWaiting", waiting)
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
353
272
0cb9869b42b6 browser_side: bug fix for RoomAndContactsChooser (do not display the MUCs in the list)
souliane <souliane@mailoo.org>
parents: 271
diff changeset
354 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
355 """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
356 @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
357 """
265
56a307f08ffe browser_side: sort the the result of ContactList.getConnected()
souliane <souliane@mailoo.org>
parents: 262
diff changeset
358 contacts = self.connected.keys()
56a307f08ffe browser_side: sort the the result of ContactList.getConnected()
souliane <souliane@mailoo.org>
parents: 262
diff changeset
359 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
360 return contacts if not filter_muc else list(set(contacts).intersection(set(self.getContacts())))
28
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
361
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
362 def getContactGroups(self, contact_jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
363 """Get groups where contact is
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
364 @param group: string of single group, or list of string
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
365 @param contact_jid: jid to test
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
366 """
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
367 result = set()
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
368 for group in self.groups:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
369 if self.isContactInGroup(group, contact_jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
370 result.add(group)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
371 return result
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
372
13
0110d4e1d816 microblog panel filtering
Goffi <goffi@goffi.org>
parents: 6
diff changeset
373 def isContactInGroup(self, group, contact_jid):
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
374 """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
375 @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
376 @param contact_jid: jid to test
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
377 @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
378 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
379 return True
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
380 return False
13
0110d4e1d816 microblog panel filtering
Goffi <goffi@goffi.org>
parents: 6
diff changeset
381
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
382 def isContactInRoster(self, contact_jid):
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
383 """Test if the contact is in our roster list"""
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
384 for _contact_label in self._contact_list:
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
385 if contact_jid == _contact_label.jid:
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
386 return True
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
387 return False
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
388
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
389 def getContacts(self):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
390 return self._contact_list.getContacts()
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
391
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
392 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
393 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
394
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
395 def onMouseMove(self, sender, x, y):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
396 pass
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
397
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
398 def onMouseDown(self, sender, x, y):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
399 pass
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
400
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
401 def onMouseUp(self, sender, x, y):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
402 pass
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
403
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
404 def onMouseEnter(self, sender):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
405 if isinstance(sender, GroupLabel):
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
406 for contact in self._contact_list:
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
407 if contact.jid in self.groups[sender.group]:
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
408 contact.addStyleName("selected")
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
409
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
410 def onMouseLeave(self, sender):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
411 if isinstance(sender, GroupLabel):
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
412 for contact in self._contact_list:
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
413 if contact.jid in self.groups[sender.group]:
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
414 contact.removeStyleName("selected")