annotate browser_side/contact.py @ 252:b77940d8a9bf

browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
author souliane <souliane@mailoo.org>
date Fri, 08 Nov 2013 17:07:27 +0100
parents a25aa882e09a
children da0487f0a2e7
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
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
22 import pyjd # this is dummy in pyjs
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.SimplePanel import SimplePanel
187
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
24 from pyjamas.ui.ScrollPanel import ScrollPanel
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.VerticalPanel import VerticalPanel
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
26 from pyjamas.ui.ClickListener import ClickHandler
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.Label import Label
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
28 from pyjamas.ui.HTML import HTML
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
29 from jid import JID
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from pyjamas import Window
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from pyjamas import DOM
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
32
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
33 from browser_side.panels import ChatPanel, MicroblogPanel, PopupMenuPanel, WebPanel
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
34 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
35 from __pyjamas__ import doc
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
36
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
37
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
38 class GroupLabel(DragLabel, Label, ClickHandler):
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
39 def __init__(self, host, group):
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
40 self.group = group
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
41 self.host = host
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
42 Label.__init__(self, group) #, Element=DOM.createElement('div')
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
43 self.setStyleName('group')
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
44 DragLabel.__init__(self, group, "GROUP")
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
45 ClickHandler.__init__(self)
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
46 self.addClickListener(self)
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
47
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
48 def onClick(self, sender):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
49 self.host.getOrCreateLiberviaWidget(MicroblogPanel, self.group)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
50
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
51
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
52 class ContactLabel(DragLabel, HTML, ClickHandler):
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
53 def __init__(self, host, jid, name=None):
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
54 HTML.__init__(self)
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
55 self.host = host
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
56 self.name = name or jid
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
57 self.waiting = False
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
58 self.jid = jid
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
59 self._fill()
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.setStyleName('contact')
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 17
diff changeset
61 DragLabel.__init__(self, jid, "CONTACT")
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
62 ClickHandler.__init__(self)
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
63 self.addClickListener(self)
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
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
77 def onClick(self, sender):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
78 self.host.getOrCreateLiberviaWidget(ChatPanel, self.jid)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
79
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
80
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
81 class GroupList(VerticalPanel):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
82
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
83 def __init__(self, parent):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
84 VerticalPanel.__init__(self)
74
3df602cf700a browser side: groups design
Adrien Vigneron <adrienvigneron@mailoo.org>
parents: 66
diff changeset
85 self.setStyleName('groupList')
2
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):
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
89 _item = GroupLabel(self._parent.host, group)
2
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)
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
98
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
99
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
100 class GenericContactList(VerticalPanel):
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
101 """Class that can be used to represent a contact list, but not necessarily
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
102 the one that is displayed on the left side. Special features like popup menu
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
103 panel or changing the contact states must be done in a sub-class."""
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
104
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
105 def __init__(self, host):
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
106 VerticalPanel.__init__(self)
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
107 self.host = host
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
108 self.contacts = set()
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
109
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
110 def add(self, jid, name=None, item_cb=None):
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
111 if jid in self.contacts:
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 self.contacts.add(jid)
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
114 _item = ContactLabel(self.host, jid, name)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
115 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
116 VerticalPanel.add(self, _item)
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
117 if item_cb is not None:
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
118 item_cb(_item)
55
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 remove(self, jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
121 wid = self.getContactLabel(jid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
122 if not wid:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
123 return
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
124 VerticalPanel.remove(self, wid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
125 self.contacts.remove(jid)
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 isContactPresent(self, contact_jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
128 """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
129 return contact_jid in self.contacts
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
130
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
131 def getContacts(self):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
132 return self.contacts
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
133
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
134 def getContactLabel(self, contact_jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
135 """get contactList widget of a contact
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
136 @return: ContactLabel item if present, else None"""
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
137 for wid in self:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
138 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
139 return wid
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
140 return None
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
141
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
142
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
143 class ContactList(GenericContactList):
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
144 """The contact list that is displayed on the left side."""
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
145
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
146 def __init__(self, host):
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
147 GenericContactList.__init__(self, host)
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
148 self.menu_entries = {"blog": {"title": "Public blog..."}}
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
149 self.context_menu = PopupMenuPanel(entries=self.menu_entries,
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
150 hide=self.contextMenuHide,
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
151 callback=self.contextMenuCallback,
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
152 vertical=False, menu_style="menu")
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
153
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
154 def contextMenuHide(self, sender, key):
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
155 """Return True if the item for that sender should be hidden."""
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
156 # TODO: enable the blogs of users that are on another server
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
157 return JID(sender.jid).domain != self.host._defaultDomain
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
158
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
159 def contextMenuCallback(self, sender, key):
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
160 if key == "blog":
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
161 # TODO: use the bare when all blogs can be retrieved
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
162 node = JID(sender.jid).node
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
163 web_panel = WebPanel(self.host, "/blog/%s" % node)
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
164 self.host.addTab(web_panel, "%s's blog" % node)
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
165 else:
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
166 sender.onClick(sender)
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
167
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
168 def add(self, jid, name=None):
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
169 def item_cb(item):
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
170 self.context_menu.registerRightClickSender(item)
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
171 GenericContactList.add(self, jid, name, item_cb)
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
172
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
173 def setState(self, jid, type_, state):
47
7cabe3c1a5f2 browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents: 33
diff changeset
174 """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
175 @param jid: jid which need to change state
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
176 @param type_: one of availability, messageWaiting
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
177 @param state:
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
178 - for messageWaiting type:
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
179 True if message are waiting
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
180 - for availability type:
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
181 '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
182 _item = self.getContactLabel(jid)
47
7cabe3c1a5f2 browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents: 33
diff changeset
183 if _item:
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
184 if type_ == 'availability':
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
185 if state == 'unavailable':
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
186 _item.removeStyleName('contactConnected')
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
187 else:
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
188 _item.addStyleName('contactConnected')
252
b77940d8a9bf browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
souliane <souliane@mailoo.org>
parents: 242
diff changeset
189 elif type_ == 'messageWaiting':
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
190 _item.setMessageWaiting(state)
47
7cabe3c1a5f2 browser side: connected contacts now appear differently
Goffi <goffi@goffi.org>
parents: 33
diff changeset
191
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
192
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
193 class ContactTitleLabel(DragLabel, Label, ClickHandler):
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
194 def __init__(self, host, text):
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
195 Label.__init__(self, text) #, Element=DOM.createElement('div')
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
196 self.host = host
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
197 self.setStyleName('contactTitle')
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 17
diff changeset
198 DragLabel.__init__(self, text, "CONTACT_TITLE")
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
199 ClickHandler.__init__(self)
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
200 self.addClickListener(self)
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
201
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
202 def onClick(self, sender):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
203 self.host.getOrCreateLiberviaWidget(MicroblogPanel, None)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
204
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
205
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
206 class ContactPanel(SimplePanel):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
207 """Manage the contacts and groups"""
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
208
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
209 def __init__(self, host):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
210 SimplePanel.__init__(self)
187
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
211
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
212 self.scroll_panel = ScrollPanel()
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
213
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
214 self.host = host
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
215 self.groups = {}
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
216 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
217
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
218 self.vPanel = VerticalPanel()
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
219 _title = ContactTitleLabel(host, 'Contacts')
16
099c05a0dcab browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents: 13
diff changeset
220 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer")
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
221
200
0f5c2f799913 browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents: 196
diff changeset
222 self._contact_list = ContactList(host)
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
223 self._contact_list.setStyleName('contactList')
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
224 self._groupList = GroupList(self)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
225 self._groupList.setStyleName('groupList')
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
226
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
227 self.vPanel.add(_title)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
228 self.vPanel.add(self._groupList)
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
229 self.vPanel.add(self._contact_list)
187
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
230 self.scroll_panel.add(self.vPanel)
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
231 self.add(self.scroll_panel)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
232 self.setStyleName('contactBox')
187
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
233 Window.addWindowResizeListener(self)
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
234
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
235 def onWindowResized(self, width, height):
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
236 contact_panel_elt = self.getElement()
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
237 _elts = doc().getElementsByClassName('gwt-TabBar')
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
238 if not _elts.length:
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
239 print ("ERROR: no TabBar found, it should exist !")
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
240 tab_bar_h = height
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
241 else:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
242 tab_bar_h = DOM.getAbsoluteTop(_elts.item(0)) or height # getAbsoluteTop can be 0 if tabBar is hidden
187
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
243
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 165
diff changeset
244 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
245 self.scroll_panel.setHeight("%s%s" % (ideal_height, "px"));
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
246
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
247 def updateContact(self, jid, attributes, groups):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
248 """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
249 @param jid: jid
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
250 @attributes: cf SàT Bridge API's newContact
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
251 @param groups: list of groups"""
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
252 _current_groups = self.getContactGroups(jid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
253 _new_groups = set(groups)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
254 _key = "@%s: "
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
255
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
256 for group in _current_groups.difference(_new_groups):
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
257 # We remove the contact from the groups where he isn't anymore
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
258 self.groups[group].remove(jid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
259 if not self.groups[group]:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
260 # The group is now empty, we must remove it
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
261 del self.groups[group]
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
262 self._groupList.remove(group)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
263 self.host.uni_box.removeKey(_key % group)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
264
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
265 for group in _new_groups.difference(_current_groups):
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
266 # We add the contact to the groups he joined
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
267 if not group in self.groups.keys():
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
268 self.groups[group] = set()
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
269 self._groupList.add(group)
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
270 self.host.uni_box.addKey(_key % group)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
271 self.groups[group].add(jid)
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
272
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
273 # 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
274 self._contact_list.add(jid)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
275
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
276 def removeContact(self, jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
277 """Remove contacts from groups where he is and contact list"""
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
278 self.updateContact(jid, {}, []) # we remove contact from every group
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
279 self._contact_list.remove(jid)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
280
28
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
281 def setConnected(self, jid, resource, availability, priority, statuses):
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
282 """Set connection status"""
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
283 if availability == 'unavailable':
28
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
284 if self.connected.has_key(jid):
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
285 if self.connected[jid].has_key(resource):
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
286 del self.connected[jid][resource]
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
287 if not self.connected[jid]:
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
288 del self.connected[jid]
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
289 else:
28
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
290 if not self.connected.has_key(jid):
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
291 self.connected[jid] = {}
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
292 self.connected[jid][resource] = (availability, priority, statuses)
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
293 self._contact_list.setState(jid, "availability", availability)
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
294
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
295 def setContactMessageWaiting(self, jid, waiting):
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
296 """Show an visual indicator that contact has send a message
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
297 @param jid: jid of the contact
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
298 @param waiting: True if message are waiting"""
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
299 self._contact_list.setState(jid, "messageWaiting", waiting)
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
300
28
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
301 def getConnected(self):
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 28
diff changeset
302 """return a list of all jid (bare jid) connected"""
28
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
303 return self.connected.keys()
258dfaa1035f browser side:
Goffi <goffi@goffi.org>
parents: 22
diff changeset
304
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
305 def getContactGroups(self, contact_jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
306 """Get groups where contact is
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
307 @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
308 @param contact_jid: jid to test
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
309 """
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
310 result = set()
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
311 for group in self.groups:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
312 if self.isContactInGroup(group, contact_jid):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
313 result.add(group)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
314 return result
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
315
13
0110d4e1d816 microblog panel filtering
Goffi <goffi@goffi.org>
parents: 6
diff changeset
316 def isContactInGroup(self, group, contact_jid):
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
317 """Test if the contact_jid is in the group
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
318 @param group: string of single group, or list of string
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
319 @param contact_jid: jid to test
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
320 @return: True if contact_jid is in on of the groups"""
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
321 if group in self.groups and contact_jid in self.groups[group]:
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
322 return True
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 230
diff changeset
323 return False
13
0110d4e1d816 microblog panel filtering
Goffi <goffi@goffi.org>
parents: 6
diff changeset
324
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
325 def isContactInRoster(self, contact_jid):
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
326 """Test if the contact is in our roster list"""
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
327 for _contact_label in self._contact_list:
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
328 if contact_jid == _contact_label.jid:
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
329 return True
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
330 return False
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
331
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
332 def getContacts(self):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
333 return self._contact_list.getContacts()
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
334
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
335 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
336 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
337
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
338 def onMouseMove(self, sender, x, y):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
339 pass
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
340
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
341 def onMouseDown(self, sender, x, y):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
342 pass
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
343
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
344 def onMouseUp(self, sender, x, y):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
345 pass
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
346
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
347 def onMouseEnter(self, sender):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
348 if isinstance(sender, GroupLabel):
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
349 for contact in self._contact_list:
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
350 if contact.jid in self.groups[sender.group]:
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
351 contact.addStyleName("selected")
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 200
diff changeset
352
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
353 def onMouseLeave(self, sender):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
354 if isinstance(sender, GroupLabel):
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 51
diff changeset
355 for contact in self._contact_list:
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
356 if contact.jid in self.groups[sender.group]:
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff changeset
357 contact.removeStyleName("selected")