comparison libervia.py @ 13:0110d4e1d816

microblog panel filtering
author Goffi <goffi@goffi.org>
date Thu, 31 Mar 2011 00:01:16 +0200
parents 331c093e4eb3
children 9bf8ed012adc
comparison
equal deleted inserted replaced
12:513fe9bd0665 13:0110d4e1d816
164 print "Empty Panel: onDrop" 164 print "Empty Panel: onDrop"
165 dt = event.dataTransfer 165 dt = event.dataTransfer
166 #'text', 'text/plain', and 'Text' are equivalent. 166 #'text', 'text/plain', and 'Text' are equivalent.
167 try: 167 try:
168 item = dt.getData("text/plain") 168 item = dt.getData("text/plain")
169 item_type = dt.getData("type")
169 print "message: %s" % item 170 print "message: %s" % item
171 print "type: %s" % item_type
170 except: 172 except:
171 print "no message found" 173 print "no message found"
172 item='&nbsp;' 174 item='&nbsp;'
175 item_type = None
173 DOM.eventPreventDefault(event) 176 DOM.eventPreventDefault(event)
174 self.host.mpanels.insert(0,MicroblogPanel(item)) 177 _mblog = MicroblogPanel(self.host, item)
178 if item_type=="GROUP":
179 _mblog.setAcceptedGroup(item)
180 self.host.mpanels.insert(0,_mblog)
175 self.host.middle_panel.changePanel(self.data,self.host.mpanels[0]) 181 self.host.middle_panel.changePanel(self.data,self.host.mpanels[0])
176 182
177 183
178 184
179 class MicroblogEntry(SimplePanel): 185 class MicroblogEntry(SimplePanel):
192 self.add(panel) 198 self.add(panel)
193 199
194 200
195 class MicroblogPanel(VerticalPanel): 201 class MicroblogPanel(VerticalPanel):
196 202
197 def __init__(self,title='&nbsp;'): 203 def __init__(self,host, title='&nbsp;', accept_all=False):
204 self.host = host
205 self.accept_all = accept_all
198 title=title.replace('<','&lt;').replace('>','&gt;') 206 title=title.replace('<','&lt;').replace('>','&gt;')
199 VerticalPanel.__init__(self) 207 VerticalPanel.__init__(self)
208 self.accepted_groups = []
200 _class = ['mb_panel_header'] 209 _class = ['mb_panel_header']
201 if title == '&nbsp;': 210 if title == '&nbsp;':
202 _class.append('empty_header') 211 _class.append('empty_header')
203 self.add(HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),title))) 212 self.add(HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),title)))
204 self.setStyleName('microblogPanel') 213 self.setStyleName('microblogPanel')
208 @param text: main text of the entry 217 @param text: main text of the entry
209 @param author: who wrote the entry 218 @param author: who wrote the entry
210 @param date: when the entry was written""" 219 @param date: when the entry was written"""
211 _entry = MicroblogEntry(text, author, timestamp) 220 _entry = MicroblogEntry(text, author, timestamp)
212 self.add(_entry) 221 self.add(_entry)
222
223 def setAcceptedGroup(self, group):
224 """Set the group which can be displayed in this panel
225 @param group: string of the group, or list of string
226 """
227 if isinstance(group, list):
228 self.accepted_groups.extend(group)
229 else:
230 self.accepted_groups.append(group)
231
232 def isJidAccepted(self, jid):
233 """Tell if a jid is actepted and show in this panel
234 @param jid: jid
235 @return: True if the jid is accepted"""
236 if self.accept_all:
237 return True
238 for group in self.accepted_groups:
239 if self.host.contactPanel.isContactInGroup(group, jid):
240 return True
241 return False
242
213 243
214 class MiddlePannel(HorizontalPanel): 244 class MiddlePannel(HorizontalPanel):
215 245
216 def __init__(self, host): 246 def __init__(self, host):
217 self.host=host 247 self.host=host
266 self.magicBox = MagicBox(self) 296 self.magicBox = MagicBox(self)
267 self.magicBox.addKey("@@: ") 297 self.magicBox.addKey("@@: ")
268 self.contactPanel = ContactPanel(self) 298 self.contactPanel = ContactPanel(self)
269 self.panel = MainPanel(self) 299 self.panel = MainPanel(self)
270 self.middle_panel = self.panel.middle_panel 300 self.middle_panel = self.panel.middle_panel
271 self.mpanels = [MicroblogPanel()] 301 self.mpanels = [MicroblogPanel(self, accept_all=True)]
272 self.middle_panel.changePanel(1,self.mpanels[0]) 302 self.middle_panel.changePanel(1,self.mpanels[0])
273 self.middle_panel.changePanel(0,EmptyPanel(self, 0)) 303 self.middle_panel.changePanel(0,EmptyPanel(self, 0))
274 self.middle_panel.changePanel(2,EmptyPanel(self, 2)) 304 self.middle_panel.changePanel(2,EmptyPanel(self, 2))
275 self._dialog = None 305 self._dialog = None
276 RootPanel().add(self.panel) 306 RootPanel().add(self.panel)
319 if event_type == "MICROBLOG": 349 if event_type == "MICROBLOG":
320 if not data.has_key('content'): 350 if not data.has_key('content'):
321 print ("WARNING: No content found in microblog data") 351 print ("WARNING: No content found in microblog data")
322 return 352 return
323 for panel in self.mpanels: 353 for panel in self.mpanels:
324 if isinstance(panel,MicroblogPanel): 354 if isinstance(panel,MicroblogPanel) and panel.isJidAccepted(sender):
355 print "sender:",sender
325 content = data['content'] 356 content = data['content']
326 author = data.get('author') 357 author = data.get('author')
327 print "timestamp: %s" % data.get('timestamp') 358 print "timestamp: %s" % data.get('timestamp')
328 timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here 359 timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here
329 panel.addEntry(content, author, timestamp) 360 panel.addEntry(content, author, timestamp)