annotate browser_side/contact.py @ 196:c2639c9f86ea

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