Mercurial > libervia-web
annotate browser_side/contact.py @ 55:d5266c41ca24
Roster list update, contact deletion + some refactoring
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 29 May 2011 02:13:53 +0200 |
parents | f25c4077f6b9 |
children | 12e889a683ce |
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 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) |
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 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from pyjamas import Window |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from pyjamas import DOM |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
6 | 30 from pyjamas.dnd import makeDraggable |
31 from pyjamas.ui.DragWidget import DragWidget, DragContainer | |
19 | 32 from jid import JID |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
34 class DragLabel(DragWidget): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
35 |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
36 def __init__(self, text, type): |
6 | 37 DragWidget.__init__(self) |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
38 self._text = text |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
39 self._type = type |
6 | 40 |
41 def onDragStart(self, event): | |
42 print "onDragStart" | |
43 dt = event.dataTransfer | |
44 #self.addMessage('types is %s' % dt.getTypes()) | |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
45 dt.setData('Text', self._text) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
46 dt.setData('type', self._type) |
6 | 47 #self.addMessage('after setting, len is %s' % len(dt.dataStore.items)) |
48 #self.addMessage('types is %s' % dt.getTypes()) | |
49 dt.setDragImage(self.getElement(), 15, 15) | |
50 #dt.effectAllowed = 'copy' | |
51 #self.addMessage('mode is %s' % dt.dataStore.items.mode) | |
52 | |
53 def onDragEnd(self, event): | |
54 print "onDragEnd" | |
55 #self.addMessage('Drag ended') | |
56 #self.addMessage('mode is %s' % dt._data.mode) | |
57 | |
58 def addMessage(self, message): | |
59 print "addMessage" | |
60 #parent = self.getParent() | |
61 #while not hasattr(parent, 'addMessage'): | |
62 # parent = parent.getParent() | |
63 #parent.addMessage(message) | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
65 class GroupLabel(DragLabel, Label): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
66 def __init__(self, group): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
67 self.group = group |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
68 Label.__init__(self, group) #, Element=DOM.createElement('div') |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
69 self.setStyleName('group') |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
70 DragLabel.__init__(self, group, "GROUP") |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
71 |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
72 |
19 | 73 class ContactLabel(DragLabel, Label): |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 def __init__(self, jid, name=None): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 if not name: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 name=jid |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
77 Label.__init__(self, name) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 self.jid=jid |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 self.setStyleName('contact') |
19 | 80 DragLabel.__init__(self, jid, "CONTACT") |
2
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 class GroupList(VerticalPanel): |
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 __init__(self, parent): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 VerticalPanel.__init__(self) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 self._parent = parent |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 def add(self, group): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 _item = GroupLabel(group) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 _item.addMouseListener(self._parent) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 VerticalPanel.add(self, _item) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
93 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
94 def remove(self, group): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
95 for wid in self: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
96 if isinstance(wid, GroupLabel) and wid.group == group: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
97 VerticalPanel.remove(self, wid) |
2
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 class ContactList(VerticalPanel): |
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 __init__(self): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 VerticalPanel.__init__(self) |
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) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 _item = ContactLabel(jid, name) |
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 |
47
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
135 def setState(self, jid, state): |
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 |
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
138 @param state: '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
|
139 _item = self.getContactLabel(jid) |
47
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
140 if _item: |
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
141 if state == 'unavailable': |
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
142 _item.removeStyleName('contactConnected') |
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
143 else: |
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
144 _item.addStyleName('contactConnected') |
7cabe3c1a5f2
browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
145 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
146 class ContactTitleLabel(DragLabel, Label): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
147 def __init__(self, text): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
148 Label.__init__(self, text) #, Element=DOM.createElement('div') |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
149 self.setStyleName('contactTitle') |
19 | 150 DragLabel.__init__(self, text, "CONTACT_TITLE") |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
151 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 class ContactPanel(SimplePanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 """Manage the contacts and groups""" |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 def __init__(self, host): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 SimplePanel.__init__(self) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 self.host = host |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 self.groups={} |
28 | 159 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
|
160 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 self.vPanel = VerticalPanel() |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
162 _title = ContactTitleLabel('Contacts') |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
163 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer") |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
165 self._contact_list = ContactList() |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
166 self._contact_list.setStyleName('contactList') |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 self._groupList = GroupList(self) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 self._groupList.setStyleName('groupList') |
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.add(_title) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 self.vPanel.add(self._groupList) |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
172 self.vPanel.add(self._contact_list) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 self.add(self.vPanel) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 self.setStyleName('contactBox') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
176 def updateContact(self, jid, attributes, groups): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
177 """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
|
178 @param jid: jid |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 @attributes: cf SàT Bridge API's newContact |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 @param groups: list of groups""" |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
181 _current_groups = self.getContactGroups(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
182 _new_groups = set(groups) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
183 _key = "@%s: " |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
184 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
185 for group in _current_groups.difference(_new_groups): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
186 #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
|
187 self.groups[group].remove(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
188 if not self.groups[group]: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
189 #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
|
190 del self.groups[group] |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
191 self._groupList.remove(group) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
192 self.host.uni_box.removeKey(_key % group) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
193 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
194 for group in _new_groups.difference(_current_groups): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
195 #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
|
196 if not self.groups.has_key(group): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 self.groups[group] = set() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 self._groupList.add(group) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
199 self.host.uni_box.addKey(_key % group) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 self.groups[group].add(jid) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
201 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
202 #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
|
203 self._contact_list.add(jid) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
205 def removeContact(self, jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
206 """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
|
207 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
|
208 self._contact_list.remove(jid) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
209 |
28 | 210 def setConnected(self, jid, resource, availability, priority, statuses): |
211 """Set connection status""" | |
212 if availability=='unavailable': | |
213 if self.connected.has_key(jid): | |
214 if self.connected[jid].has_key(resource): | |
215 del self.connected[jid][resource] | |
216 if not self.connected[jid]: | |
217 del self.connected[jid] | |
218 else: | |
219 if not self.connected.has_key(jid): | |
220 self.connected[jid] = {} | |
221 self.connected[jid][resource] = (availability, priority, statuses) | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
222 self._contact_list.setState(jid, availability) |
28 | 223 |
224 def getConnected(self): | |
33 | 225 """return a list of all jid (bare jid) connected""" |
28 | 226 return self.connected.keys() |
227 | |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
228 def getContactGroups(self, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
229 """Get groups where contact is |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
230 @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
|
231 @param contact_jid: jid to test |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
232 """ |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
233 result=set() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
234 for group in self.groups: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
235 if self.isContactInGroup(group, contact_jid): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
236 result.add(group) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
237 return result |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
238 |
13 | 239 def isContactInGroup(self, group, contact_jid): |
240 """Test if the contact_jid is in the group | |
241 @param group: string of single group, or list of string | |
242 @param contact_jid: jid to test | |
243 @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
|
244 if group in self.groups and contact_jid in self.groups[group]: |
13 | 245 return True |
246 return False | |
247 | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
248 def isContactInRoster(self, contact_jid): |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
249 """Test if the contact is in our roster list""" |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
250 for _contact_label in self._contact_list: |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
251 if contact_jid == _contact_label.jid: |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
252 return True |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
253 return False |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
254 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
255 def getContacts(self): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
256 return self._contact_list.getContacts() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
257 |
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
|
258 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
|
259 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
|
260 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 def onMouseMove(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 def onMouseDown(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 def onMouseUp(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 def onMouseEnter(self, sender): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 if isinstance(sender, GroupLabel): |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
272 for contact in self._contact_list: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 if contact.jid in self.groups[sender.group]: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 contact.addStyleName("selected") |
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 onMouseLeave(self, sender): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 if isinstance(sender, GroupLabel): |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
278 for contact in self._contact_list: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 if contact.jid in self.groups[sender.group]: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 contact.removeStyleName("selected") |