Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_chat.py @ 184:c63922860f80
chat: show desktop notification and/or note when suitable
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 10 May 2018 08:32:46 +0200 |
parents | 0ddd2b20cc6b |
children | ab3f5173ef5c |
comparison
equal
deleted
inserted
replaced
183:6f09bc00a9e7 | 184:c63922860f80 |
---|---|
32 from sat_frontends.tools import jid | 32 from sat_frontends.tools import jid |
33 from cagou.core import cagou_widget | 33 from cagou.core import cagou_widget |
34 from cagou.core.image import Image | 34 from cagou.core.image import Image |
35 from cagou.core.common import SymbolButton, JidItem | 35 from cagou.core.common import SymbolButton, JidItem |
36 from kivy.uix.dropdown import DropDown | 36 from kivy.uix.dropdown import DropDown |
37 from kivy.core.window import Window | |
37 from cagou import G | 38 from cagou import G |
38 import mimetypes | 39 import mimetypes |
39 | 40 |
40 | 41 |
41 PLUGIN_INFO = { | 42 PLUGIN_INFO = { |
349 def createMessage(self, message): | 350 def createMessage(self, message): |
350 self.appendMessage(message) | 351 self.appendMessage(message) |
351 | 352 |
352 def appendMessage(self, mess_data): | 353 def appendMessage(self, mess_data): |
353 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data)) | 354 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data)) |
355 self.notify(mess_data) | |
356 | |
357 def _get_notif_msg(self, mess_data): | |
358 return _(u"{nick}: {message}").format( | |
359 nick=mess_data.nick, | |
360 message=mess_data.main_message) | |
361 | |
362 def notify(self, mess_data): | |
363 """Notify user when suitable | |
364 | |
365 For one2one chat, notification will happen when window has not focus | |
366 or when one2one chat is not visible. A note is also there when widget | |
367 is not visible. | |
368 For group chat, note will be added on mention, with a desktop notification if | |
369 window has not focus. | |
370 """ | |
371 if self.type == C.CHAT_ONE2ONE: | |
372 is_visible = self.target in [w.target for w in G.host.getVisibleList(self.__class__)] | |
373 if (not Window.focus or not is_visible) and not mess_data.history: | |
374 notif_msg = self._get_notif_msg(mess_data) | |
375 G.host.desktop_notif( | |
376 notif_msg, | |
377 title=_(u"private message")) | |
378 if not is_visible: | |
379 G.host.addNote( | |
380 _(u"private message"), | |
381 notif_msg | |
382 ) | |
383 else: | |
384 if mess_data.mention and not mess_data.history: | |
385 notif_msg = self._get_notif_msg(mess_data) | |
386 G.host.addNote( | |
387 _(u"mention"), | |
388 notif_msg | |
389 ) | |
390 if not Window.focus: | |
391 G.host.desktop_notif( | |
392 notif_msg, | |
393 title=_(u"mention ({room_jid})").format( | |
394 room_jid=self.target) | |
395 ) | |
354 | 396 |
355 def onSend(self, input_widget): | 397 def onSend(self, input_widget): |
356 G.host.messageSend( | 398 G.host.messageSend( |
357 self.target, | 399 self.target, |
358 {'': input_widget.text}, # TODO: handle language | 400 {'': input_widget.text}, # TODO: handle language |