Mercurial > libervia-web
annotate browser_side/contact.py @ 195:dd27072d8ae0
browser side: widgets refactoring:
- moved base widgets in a base_widget module
- widgets class now register themselves their Drag/Drop type
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 04 Mar 2013 23:01:57 +0100 |
parents | d0503f8f15ef |
children | c2639c9f86ea |
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 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
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 |
6 | 32 from pyjamas.ui.DragWidget import DragWidget, DragContainer |
62 | 33 from browser_side.tools import html_sanitize |
19 | 34 from jid import JID |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
35 from __pyjamas__ import doc |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
37 class DragLabel(DragWidget): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
38 |
195 | 39 def __init__(self, text, _type): |
6 | 40 DragWidget.__init__(self) |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
41 self._text = text |
195 | 42 self._type = _type |
6 | 43 |
44 def onDragStart(self, event): | |
45 dt = event.dataTransfer | |
62 | 46 dt.setData('text/plain', "%s\n%s" % (self._text, self._type)) |
6 | 47 dt.setDragImage(self.getElement(), 15, 15) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
49 class GroupLabel(DragLabel, Label): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
50 def __init__(self, group): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
51 self.group = group |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
52 Label.__init__(self, group) #, Element=DOM.createElement('div') |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
53 self.setStyleName('group') |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
54 DragLabel.__init__(self, group, "GROUP") |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
55 |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
56 |
62 | 57 class ContactLabel(DragLabel, HTML): |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 def __init__(self, jid, name=None): |
62 | 59 HTML.__init__(self) |
60 self.name = name or jid | |
61 self.waiting = False | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 self.jid=jid |
62 | 63 self._fill() |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 self.setStyleName('contact') |
19 | 65 DragLabel.__init__(self, jid, "CONTACT") |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
62 | 67 def _fill(self): |
68 if self.waiting: | |
69 _wait_html = "<b>(*)</b> " | |
70 self.setHTML("%(wait)s%(name)s" % {'wait': _wait_html, | |
71 'name': html_sanitize(self.name)}) | |
72 | |
73 def setMessageWaiting(self, waiting): | |
74 """Show a visual indicator if message are waiting | |
75 @param waiting: True if message are waiting""" | |
76 self.waiting = waiting | |
77 self._fill() | |
78 | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 class GroupList(VerticalPanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 def __init__(self, parent): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 VerticalPanel.__init__(self) |
74
3df602cf700a
browser side: groups design
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
66
diff
changeset
|
83 self.setStyleName('groupList') |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 self._parent = parent |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 def add(self, group): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 _item = GroupLabel(group) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 _item.addMouseListener(self._parent) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 VerticalPanel.add(self, _item) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
91 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
92 def remove(self, group): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
93 for wid in self: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
94 if isinstance(wid, GroupLabel) and wid.group == group: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
95 VerticalPanel.remove(self, wid) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 class ContactList(VerticalPanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 def __init__(self): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 VerticalPanel.__init__(self) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
101 self.contacts = set() |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 def add(self, jid, name=None): |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
104 if jid in self.contacts: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
105 return |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
106 self.contacts.add(jid) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 _item = ContactLabel(jid, name) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 VerticalPanel.add(self, _item) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
110 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
111 def remove(self, jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
112 wid = self.getContactLabel(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
113 if not wid: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
114 return |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
115 VerticalPanel.remove(self, wid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
116 self.contacts.remove(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
117 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
118 def isContactPresent(self, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
119 """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
|
120 return contact_jid in self.contacts |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
121 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
122 def getContacts(self): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
123 return self.contacts |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
124 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
125 def getContactLabel(self, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
126 """get contactList widget of a contact |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
127 @return: ContactLabel item if present, else None""" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
128 for wid in self: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
129 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
|
130 return wid |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
131 return None |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 |
62 | 133 def setState(self, jid, type, state): |
47
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
134 """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
|
135 @param jid: jid which need to change state |
62 | 136 @param type: one of availability, messageWaiting |
137 @param state: | |
138 - for messageWaiting type: | |
139 True if message are waiting | |
140 - for availability type: | |
141 '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
|
142 _item = self.getContactLabel(jid) |
47
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
143 if _item: |
62 | 144 if type == 'availability': |
145 if state == 'unavailable': | |
146 _item.removeStyleName('contactConnected') | |
147 else: | |
148 _item.addStyleName('contactConnected') | |
149 elif type == 'messageWaiting': | |
150 _item.setMessageWaiting(state) | |
47
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
151 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
152 class ContactTitleLabel(DragLabel, Label): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
153 def __init__(self, text): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
154 Label.__init__(self, text) #, Element=DOM.createElement('div') |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
155 self.setStyleName('contactTitle') |
19 | 156 DragLabel.__init__(self, text, "CONTACT_TITLE") |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
157 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 class ContactPanel(SimplePanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 """Manage the contacts and groups""" |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 def __init__(self, host): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 SimplePanel.__init__(self) |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
163 |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
164 self.scroll_panel = ScrollPanel() |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
165 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 self.host = host |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 self.groups={} |
28 | 168 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
|
169 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 self.vPanel = VerticalPanel() |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
171 _title = ContactTitleLabel('Contacts') |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
172 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer") |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
174 self._contact_list = ContactList() |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
175 self._contact_list.setStyleName('contactList') |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 self._groupList = GroupList(self) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 self._groupList.setStyleName('groupList') |
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.add(_title) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 self.vPanel.add(self._groupList) |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
181 self.vPanel.add(self._contact_list) |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
182 self.scroll_panel.add(self.vPanel) |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
183 self.add(self.scroll_panel) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 self.setStyleName('contactBox') |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
185 Window.addWindowResizeListener(self) |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
186 |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
187 def onWindowResized(self, width, height): |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
188 contact_panel_elt = self.getElement() |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
189 _elts = doc().getElementsByClassName('gwt-TabBar') |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
190 if not _elts.length: |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
191 print ("ERROR: no TabBar found, it should exist !") |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
192 tab_bar_h = height |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
193 else: |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
194 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
|
195 |
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
196 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
|
197 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
|
198 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
200 def updateContact(self, jid, attributes, groups): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
201 """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
|
202 @param jid: jid |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 @attributes: cf SàT Bridge API's newContact |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 @param groups: list of groups""" |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
205 _current_groups = self.getContactGroups(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
206 _new_groups = set(groups) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
207 _key = "@%s: " |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
208 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
209 for group in _current_groups.difference(_new_groups): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
210 #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
|
211 self.groups[group].remove(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
212 if not self.groups[group]: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
213 #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
|
214 del self.groups[group] |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
215 self._groupList.remove(group) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
216 self.host.uni_box.removeKey(_key % group) |
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 _new_groups.difference(_current_groups): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
219 #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
|
220 if not self.groups.has_key(group): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 self.groups[group] = set() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 self._groupList.add(group) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
223 self.host.uni_box.addKey(_key % group) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 self.groups[group].add(jid) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
225 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
226 #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
|
227 self._contact_list.add(jid) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
229 def removeContact(self, jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
230 """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
|
231 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
|
232 self._contact_list.remove(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
233 |
28 | 234 def setConnected(self, jid, resource, availability, priority, statuses): |
235 """Set connection status""" | |
236 if availability=='unavailable': | |
237 if self.connected.has_key(jid): | |
238 if self.connected[jid].has_key(resource): | |
239 del self.connected[jid][resource] | |
240 if not self.connected[jid]: | |
241 del self.connected[jid] | |
242 else: | |
243 if not self.connected.has_key(jid): | |
244 self.connected[jid] = {} | |
245 self.connected[jid][resource] = (availability, priority, statuses) | |
62 | 246 self._contact_list.setState(jid, "availability", availability) |
247 | |
248 def setContactMessageWaiting(self, jid, waiting): | |
249 """Show an visual indicator that contact has send a message | |
250 @param jid: jid of the contact | |
251 @param waiting: True if message are waiting""" | |
252 self._contact_list.setState(jid, "messageWaiting", waiting) | |
253 | |
254 | |
28 | 255 |
256 def getConnected(self): | |
33 | 257 """return a list of all jid (bare jid) connected""" |
28 | 258 return self.connected.keys() |
259 | |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
260 def getContactGroups(self, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
261 """Get groups where contact is |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
262 @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
|
263 @param contact_jid: jid to test |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
264 """ |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
265 result=set() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
266 for group in self.groups: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
267 if self.isContactInGroup(group, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
268 result.add(group) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
269 return result |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
270 |
13 | 271 def isContactInGroup(self, group, contact_jid): |
272 """Test if the contact_jid is in the group | |
273 @param group: string of single group, or list of string | |
274 @param contact_jid: jid to test | |
275 @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
|
276 if group in self.groups and contact_jid in self.groups[group]: |
13 | 277 return True |
278 return False | |
279 | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
280 def isContactInRoster(self, contact_jid): |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
281 """Test if the contact is in our roster list""" |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
282 for _contact_label in self._contact_list: |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
283 if contact_jid == _contact_label.jid: |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
284 return True |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
285 return False |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
286 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
287 def getContacts(self): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
288 return self._contact_list.getContacts() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
289 |
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
|
290 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
|
291 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
|
292 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 def onMouseMove(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 def onMouseDown(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 def onMouseUp(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 def onMouseEnter(self, sender): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 if isinstance(sender, GroupLabel): |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
304 for contact in self._contact_list: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 if contact.jid in self.groups[sender.group]: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 contact.addStyleName("selected") |
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 onMouseLeave(self, sender): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 if isinstance(sender, GroupLabel): |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
310 for contact in self._contact_list: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 if contact.jid in self.groups[sender.group]: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 contact.removeStyleName("selected") |