Mercurial > libervia-web
annotate contact.py @ 10:c28a4840e1a8
server: microblog resource
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 25 Mar 2011 00:32:58 +0100 |
parents | a663b9955cf3 |
children | 0110d4e1d816 |
rev | line source |
---|---|
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 import pyjd # this is dummy in pyjs |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from pyjamas.ui.SimplePanel import SimplePanel |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from pyjamas.ui.VerticalPanel import VerticalPanel |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from pyjamas.ui.Label import Label |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from pyjamas import Window |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from pyjamas import DOM |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
6 | 30 from pyjamas.dnd import makeDraggable |
31 from pyjamas.ui.DragWidget import DragWidget, DragContainer | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
6 | 33 class GroupLabel(DragWidget, Label): |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 def __init__(self, group): |
6 | 35 Label.__init__(self, group) #, Element=DOM.createElement('div') |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 self.group = group |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 self.setStyleName('group') |
6 | 38 DragWidget.__init__(self) |
39 | |
40 def onDragStart(self, event): | |
41 print "onDragStart" | |
42 dt = event.dataTransfer | |
43 #self.addMessage('types is %s' % dt.getTypes()) | |
44 dt.setData('Text', self.group) | |
45 #self.addMessage('after setting, len is %s' % len(dt.dataStore.items)) | |
46 #self.addMessage('types is %s' % dt.getTypes()) | |
47 dt.setDragImage(self.getElement(), 15, 15) | |
48 #dt.effectAllowed = 'copy' | |
49 #self.addMessage('mode is %s' % dt.dataStore.items.mode) | |
50 | |
51 def onDragEnd(self, event): | |
52 print "onDragEnd" | |
53 #self.addMessage('Drag ended') | |
54 #self.addMessage('mode is %s' % dt._data.mode) | |
55 | |
56 def addMessage(self, message): | |
57 print "addMessage" | |
58 #parent = self.getParent() | |
59 #while not hasattr(parent, 'addMessage'): | |
60 # parent = parent.getParent() | |
61 #parent.addMessage(message) | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 class ContactLabel(Label): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 def __init__(self, jid, name=None): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 if not name: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 name=jid |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 Label.__init__(self, name) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 self.jid=jid |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 self.setStyleName('contact') |
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 class GroupList(VerticalPanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 def __init__(self, parent): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 VerticalPanel.__init__(self) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 self._parent = parent |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 def add(self, group): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 _item = GroupLabel(group) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 _item.addMouseListener(self._parent) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 VerticalPanel.add(self, _item) |
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 class ContactList(VerticalPanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 def __init__(self): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 VerticalPanel.__init__(self) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 self.contacts=[] |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 def __iter__(self): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 return self.contacts.__iter__() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 def add(self, jid, name=None): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 _item = ContactLabel(jid, name) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 VerticalPanel.add(self, _item) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 self.contacts.append(_item) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 class ContactPanel(SimplePanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 """Manage the contacts and groups""" |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 def __init__(self, host): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 SimplePanel.__init__(self) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 self.host = host |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 self.groups={} |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 self.vPanel = VerticalPanel() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 _title = Label('Contacts') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 _title.setStyleName('contactTitle') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 self._contactList = ContactList() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 self._contactList.setStyleName('contactList') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 self._groupList = GroupList(self) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 self._groupList.setStyleName('groupList') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 self.vPanel.add(_title) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 self.vPanel.add(self._groupList) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 self.vPanel.add(self._contactList) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 self.add(self.vPanel) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 self.setStyleName('contactBox') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 def addContact(self, jid, attributes, groups): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 """Add a contact to the panel |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 @param jid: jid |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 @attributes: cf SàT Bridge API's newContact |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 @param groups: list of groups""" |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 for group in groups: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 if not self.groups.has_key(group): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 self.groups[group] = set() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 self._groupList.add(group) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 self.host.magicBox.addKey("@%s: " % group) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 self.groups[group].add(jid) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 self._contactList.add(jid) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 def onMouseMove(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 def onMouseDown(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 def onMouseUp(self, sender, x, y): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 pass |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 def onMouseEnter(self, sender): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 if isinstance(sender, GroupLabel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 for contact in self._contactList: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 if contact.jid in self.groups[sender.group]: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 contact.addStyleName("selected") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 def onMouseLeave(self, sender): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 if isinstance(sender, GroupLabel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 for contact in self._contactList: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 if contact.jid in self.groups[sender.group]: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 contact.removeStyleName("selected") |