Mercurial > libervia-web
annotate browser_side/contact.py @ 215:e830a0c60d32
server side: added the security_limit to setParam
- in addition to the check which is done by the core, libervia checks if the param to be modified was really part of the XML that has been returned by getParams with security_limit = 0.
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 07 Sep 2013 02:07:07 +0200 |
parents | 0f5c2f799913 |
children | 744426c2b699 |
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 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
165 | 6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org> |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 import pyjd # this is dummy in pyjs |
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 | 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 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
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
|
32 from browser_side.panels import ChatPanel, MicroblogPanel |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
33 from browser_side.tools import DragLabel, html_sanitize |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
34 from __pyjamas__ import doc |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
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
|
36 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
|
37 def __init__(self, host, group): |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
38 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
|
39 self.host = host |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
40 Label.__init__(self, group) #, Element=DOM.createElement('div') |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
41 self.setStyleName('group') |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 |
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
|
46 def onClick(self, sender): |
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
|
47 new_wid = MicroblogPanel.createGroup(self.host, self.group) |
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
|
48 self.host.addWidget(new_wid) |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
49 |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
50 |
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
|
51 class ContactLabel(DragLabel, HTML, 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
|
52 def __init__(self, host, jid, name=None): |
62 | 53 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
|
54 self.host = host |
62 | 55 self.name = name or jid |
56 self.waiting = False | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 self.jid=jid |
62 | 58 self._fill() |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 self.setStyleName('contact') |
19 | 60 DragLabel.__init__(self, jid, "CONTACT") |
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
|
61 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
|
62 self.addClickListener(self) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
62 | 64 def _fill(self): |
65 if self.waiting: | |
66 _wait_html = "<b>(*)</b> " | |
67 self.setHTML("%(wait)s%(name)s" % {'wait': _wait_html, | |
68 'name': html_sanitize(self.name)}) | |
69 | |
70 def setMessageWaiting(self, waiting): | |
71 """Show a visual indicator if message are waiting | |
72 @param waiting: True if message are waiting""" | |
73 self.waiting = waiting | |
74 self._fill() | |
75 | |
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 def onClick(self, sender): |
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
|
77 new_wid = ChatPanel.createChat(self.host, self.jid) |
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
|
78 self.host.addWidget(new_wid) |
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 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 class GroupList(VerticalPanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 def __init__(self, parent): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 VerticalPanel.__init__(self) |
74
3df602cf700a
browser side: groups design
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
66
diff
changeset
|
84 self.setStyleName('groupList') |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 self._parent = parent |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 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
|
88 _item = GroupLabel(self._parent.host, group) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 _item.addMouseListener(self._parent) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 VerticalPanel.add(self, _item) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
92 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
93 def remove(self, group): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
94 for wid in self: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
95 if isinstance(wid, GroupLabel) and wid.group == group: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
96 VerticalPanel.remove(self, wid) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 class ContactList(VerticalPanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 |
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
|
100 def __init__(self, host): |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 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
|
102 self.host = host |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
103 self.contacts = set() |
2
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 add(self, jid, name=None): |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
106 if jid in self.contacts: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
107 return |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
108 self.contacts.add(jid) |
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
|
109 _item = ContactLabel(self.host, jid, name) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 VerticalPanel.add(self, _item) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
112 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
113 def remove(self, jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
114 wid = self.getContactLabel(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
115 if not wid: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
116 return |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
117 VerticalPanel.remove(self, wid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
118 self.contacts.remove(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
119 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
120 def isContactPresent(self, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
121 """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
|
122 return contact_jid in self.contacts |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
123 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
124 def getContacts(self): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
125 return self.contacts |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
126 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
127 def getContactLabel(self, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
128 """get contactList widget of a contact |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
129 @return: ContactLabel item if present, else None""" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
130 for wid in self: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
131 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
|
132 return wid |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
133 return None |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
62 | 135 def setState(self, jid, type, state): |
47
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
136 """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
|
137 @param jid: jid which need to change state |
62 | 138 @param type: one of availability, messageWaiting |
139 @param state: | |
140 - for messageWaiting type: | |
141 True if message are waiting | |
142 - for availability type: | |
143 '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
|
144 _item = self.getContactLabel(jid) |
47
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
145 if _item: |
62 | 146 if type == 'availability': |
147 if state == 'unavailable': | |
148 _item.removeStyleName('contactConnected') | |
149 else: | |
150 _item.addStyleName('contactConnected') | |
151 elif type == 'messageWaiting': | |
152 _item.setMessageWaiting(state) | |
47
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
153 |
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
|
154 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
|
155 def __init__(self, host, text): |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
156 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
|
157 self.host = host |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
158 self.setStyleName('contactTitle') |
19 | 159 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
|
160 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
|
161 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
|
162 |
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
|
163 def onClick(self, sender): |
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
|
164 new_wid = MicroblogPanel.createMeta(self.host, None) |
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
|
165 self.host.addWidget(new_wid) |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
166 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 class ContactPanel(SimplePanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 """Manage the contacts and groups""" |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 def __init__(self, host): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 SimplePanel.__init__(self) |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
172 |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
173 self.scroll_panel = ScrollPanel() |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
174 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 self.host = host |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 self.groups={} |
28 | 177 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
|
178 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 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
|
180 _title = ContactTitleLabel(host, 'Contacts') |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
181 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer") |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
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
|
183 self._contact_list = ContactList(host) |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
184 self._contact_list.setStyleName('contactList') |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 self._groupList = GroupList(self) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 self._groupList.setStyleName('groupList') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 self.vPanel.add(_title) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 self.vPanel.add(self._groupList) |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
190 self.vPanel.add(self._contact_list) |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
191 self.scroll_panel.add(self.vPanel) |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
192 self.add(self.scroll_panel) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 self.setStyleName('contactBox') |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
194 Window.addWindowResizeListener(self) |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
195 |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
196 def onWindowResized(self, width, height): |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
197 contact_panel_elt = self.getElement() |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
198 _elts = doc().getElementsByClassName('gwt-TabBar') |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
199 if not _elts.length: |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
200 print ("ERROR: no TabBar found, it should exist !") |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
201 tab_bar_h = height |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
202 else: |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
203 tab_bar_h = DOM.getAbsoluteTop( _elts.item(0)) or height #getAbsoluteTop can be 0 if tabBar is hidden |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
204 |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
205 ideal_height = tab_bar_h - DOM.getAbsoluteTop(contact_panel_elt) - 5 |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
206 self.scroll_panel.setHeight("%s%s" % (ideal_height, "px")); |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
207 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
209 def updateContact(self, jid, attributes, groups): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
210 """Add a contact to the panel if it doesn't exist, update it else |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 @param jid: jid |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 @attributes: cf SàT Bridge API's newContact |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 @param groups: list of groups""" |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
214 _current_groups = self.getContactGroups(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
215 _new_groups = set(groups) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
216 _key = "@%s: " |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
217 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
218 for group in _current_groups.difference(_new_groups): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
219 #We remove the contact from the groups where he isn't anymore |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
220 self.groups[group].remove(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
221 if not self.groups[group]: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
222 #The group is now empty, we must remove it |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
223 del self.groups[group] |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
224 self._groupList.remove(group) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
225 self.host.uni_box.removeKey(_key % group) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
226 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
227 for group in _new_groups.difference(_current_groups): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
228 #We add the contact to the groups he joined |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 if not self.groups.has_key(group): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 self.groups[group] = set() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 self._groupList.add(group) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
232 self.host.uni_box.addKey(_key % group) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 self.groups[group].add(jid) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
234 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
235 #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
|
236 self._contact_list.add(jid) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
238 def removeContact(self, jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
239 """Remove contacts from groups where he is and contact list""" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
240 self.updateContact(jid, {}, []) #we remove contact from every group |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
241 self._contact_list.remove(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
242 |
28 | 243 def setConnected(self, jid, resource, availability, priority, statuses): |
244 """Set connection status""" | |
245 if availability=='unavailable': | |
246 if self.connected.has_key(jid): | |
247 if self.connected[jid].has_key(resource): | |
248 del self.connected[jid][resource] | |
249 if not self.connected[jid]: | |
250 del self.connected[jid] | |
251 else: | |
252 if not self.connected.has_key(jid): | |
253 self.connected[jid] = {} | |
254 self.connected[jid][resource] = (availability, priority, statuses) | |
62 | 255 self._contact_list.setState(jid, "availability", availability) |
256 | |
257 def setContactMessageWaiting(self, jid, waiting): | |
258 """Show an visual indicator that contact has send a message | |
259 @param jid: jid of the contact | |
260 @param waiting: True if message are waiting""" | |
261 self._contact_list.setState(jid, "messageWaiting", waiting) | |
262 | |
263 | |
28 | 264 |
265 def getConnected(self): | |
33 | 266 """return a list of all jid (bare jid) connected""" |
28 | 267 return self.connected.keys() |
268 | |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
269 def getContactGroups(self, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
270 """Get groups where contact is |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
271 @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
|
272 @param contact_jid: jid to test |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
273 """ |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
274 result=set() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
275 for group in self.groups: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
276 if self.isContactInGroup(group, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
277 result.add(group) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
278 return result |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
279 |
13 | 280 def isContactInGroup(self, group, contact_jid): |
281 """Test if the contact_jid is in the group | |
282 @param group: string of single group, or list of string | |
283 @param contact_jid: jid to test | |
284 @return: True if contact_jid is in on of the groups""" | |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
285 if group in self.groups and contact_jid in self.groups[group]: |
13 | 286 return True |
287 return False | |
288 | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
289 def isContactInRoster(self, contact_jid): |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
290 """Test if the contact is in our roster list""" |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
291 for _contact_label in self._contact_list: |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
292 if contact_jid == _contact_label.jid: |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
293 return True |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
294 return False |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
295 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
296 def getContacts(self): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
297 return self._contact_list.getContacts() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
298 |
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
|
299 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
|
300 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
|
301 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 def onMouseMove(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 def onMouseDown(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 def onMouseUp(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 def onMouseEnter(self, sender): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 if isinstance(sender, GroupLabel): |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
313 for contact in self._contact_list: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 if contact.jid in self.groups[sender.group]: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 contact.addStyleName("selected") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 def onMouseLeave(self, sender): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 if isinstance(sender, GroupLabel): |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
319 for contact in self._contact_list: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 if contact.jid in self.groups[sender.group]: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 contact.removeStyleName("selected") |