comparison frontends/src/primitivus/chat.py @ 1386:1f3513cfb246

quick_frontend, primivitus: remove QuickChat.getUserNick + primivitus ChatText gets the user nick directly from parent Chat instance
author souliane <souliane@mailoo.org>
date Mon, 23 Mar 2015 15:38:32 +0100
parents 59c48796759e
children a025242bebe7
comparison
equal deleted inserted replaced
1385:0dca4f9b264d 1386:1f3513cfb246
35 35
36 36
37 class ChatText(urwid.FlowWidget): 37 class ChatText(urwid.FlowWidget):
38 """Manage the printing of chat message""" 38 """Manage the printing of chat message"""
39 39
40 def __init__(self, parent, timestamp, nick, my_mess, message, align='left', is_info=False): 40 def __init__(self, parent, timestamp, my_mess, message, align='left', is_info=False):
41 self.parent = parent 41 self.parent = parent
42 self.timestamp = time.localtime(timestamp) 42 self.timestamp = time.localtime(timestamp)
43 self.nick = nick
44 self.my_mess = my_mess 43 self.my_mess = my_mess
45 self.message = unicode(message) 44 self.message = unicode(message)
46 self.align = align 45 self.align = align
47 self.is_info = is_info 46 self.is_info = is_info
48 47
71 time_format = "%c" if self.timestamp < self.parent.day_change else "%H:%M" # if the message was sent before today, we print the full date 70 time_format = "%c" if self.timestamp < self.parent.day_change else "%H:%M" # if the message was sent before today, we print the full date
72 render_txt.append(('date', "[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8'))) 71 render_txt.append(('date', "[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8')))
73 if self.parent.show_short_nick: 72 if self.parent.show_short_nick:
74 render_txt.append(('my_nick' if self.my_mess else 'other_nick', "**" if self.my_mess else "*")) 73 render_txt.append(('my_nick' if self.my_mess else 'other_nick', "**" if self.my_mess else "*"))
75 else: 74 else:
76 render_txt.append(('my_nick' if self.my_mess else 'other_nick', "[%s] " % self.nick)) 75 render_txt.append(('my_nick' if self.my_mess else 'other_nick', "[%s] " % self.parent.nick))
77 render_txt.append(self.message) 76 render_txt.append(self.message)
78 txt_widget = urwid.Text(render_txt, align=self.align) 77 txt_widget = urwid.Text(render_txt, align=self.align)
79 if self.is_info: 78 if self.is_info:
80 return urwid.AttrMap(txt_widget, 'info_msg') 79 return urwid.AttrMap(txt_widget, 'info_msg')
81 return txt_widget 80 return txt_widget
168 self.host.redraw() 167 self.host.redraw()
169 168
170 def _occupantsClicked(self, list_wid, clicked_wid): 169 def _occupantsClicked(self, list_wid, clicked_wid):
171 assert self.type == C.CHAT_GROUP 170 assert self.type == C.CHAT_GROUP
172 nick = clicked_wid.getValue().value 171 nick = clicked_wid.getValue().value
173 if nick == self.getUserNick(): 172 if nick == self.nick:
174 # We ignore clicks on our own nick 173 # We ignore clicks on our own nick
175 return 174 return
176 contact_list = self.host.contact_lists[self.profile] 175 contact_list = self.host.contact_lists[self.profile]
177 full_jid = jid.JID("%s/%s" % (self.target.bare, nick)) 176 full_jid = jid.JID("%s/%s" % (self.target.bare, nick))
178 177
261 try: 260 try:
262 nick, mymess = QuickChat.printMessage(self, from_jid, msg, extra, profile) 261 nick, mymess = QuickChat.printMessage(self, from_jid, msg, extra, profile)
263 except TypeError: 262 except TypeError:
264 # None is returned, the message is managed 263 # None is returned, the message is managed
265 return 264 return
266 new_text = ChatText(self, timestamp, nick, mymess, msg) 265 new_text = ChatText(self, timestamp, mymess, msg)
267 266
268 if timestamp and self.content: 267 if timestamp and self.content:
269 for idx in range(len(self.content) - 1, -1, -1): 268 for idx in range(len(self.content) - 1, -1, -1):
270 current_text = self.content[idx] 269 current_text = self.content[idx]
271 older = new_text.timestamp < current_text.timestamp 270 older = new_text.timestamp < current_text.timestamp
301 extra = {} 300 extra = {}
302 try: 301 try:
303 timestamp = float(extra['timestamp']) 302 timestamp = float(extra['timestamp'])
304 except KeyError: 303 except KeyError:
305 timestamp = None 304 timestamp = None
306 _widget = ChatText(self, timestamp, None, False, msg, is_info=True) 305 _widget = ChatText(self, timestamp, False, msg, is_info=True)
307 self.content.append(_widget) 306 self.content.append(_widget)
308 self._notify(msg=msg) 307 self._notify(msg=msg)
309 308
310 def _notify(self, from_jid="somebody", msg=""): 309 def _notify(self, from_jid="somebody", msg=""):
311 """Notify the user of a new message if primitivus doesn't have the focus. 310 """Notify the user of a new message if primitivus doesn't have the focus.
320 self.text_list.focus_position = len(self.content) - 1 319 self.text_list.focus_position = len(self.content) - 1
321 self.host.redraw() 320 self.host.redraw()
322 if not self.host.x_notify.hasFocus(): 321 if not self.host.x_notify.hasFocus():
323 if self.type == C.CHAT_ONE2ONE: 322 if self.type == C.CHAT_ONE2ONE:
324 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid) 323 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid)
325 elif self.getUserNick().lower() in msg.lower(): 324 elif self.nick.lower() in msg.lower():
326 self.host.x_notify.sendNotification(_("Primitivus: %(user)s mentioned you in room '%(room)s'") % {'user': from_jid, 'room': self.target}) 325 self.host.x_notify.sendNotification(_("Primitivus: %(user)s mentioned you in room '%(room)s'") % {'user': from_jid, 'room': self.target})
327 326
328 # MENU EVENTS # 327 # MENU EVENTS #
329 def onTarotRequest(self, menu): 328 def onTarotRequest(self, menu):
330 # TODO: move this to plugin_misc_tarot with dynamic menu 329 # TODO: move this to plugin_misc_tarot with dynamic menu