annotate browser_side/contact.py @ 173:3d998119237e

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