Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_app.py @ 1347:ba41a81d14c2 frontends_multi_profiles
frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 03 Mar 2015 15:05:10 +0100 |
parents | b26dd78de495 |
children | a39d2db03c80 |
comparison
equal
deleted
inserted
replaced
1346:35f99c90b736 | 1347:ba41a81d14c2 |
---|---|
20 from sat.core.log import getLogger | 20 from sat.core.log import getLogger |
21 log = getLogger(__name__) | 21 log = getLogger(__name__) |
22 | 22 |
23 from sat.core.i18n import _ | 23 from sat.core.i18n import _ |
24 from sat.core import exceptions | 24 from sat.core import exceptions |
25 from sat.tools.misc import TriggerManager | |
25 | 26 |
26 from sat_frontends.tools import jid | 27 from sat_frontends.tools import jid |
27 from sat_frontends.quick_frontend.quick_widgets import QuickWidgetsManager | 28 from sat_frontends.quick_frontend.quick_widgets import QuickWidgetsManager |
28 from sat_frontends.quick_frontend import quick_chat | 29 from sat_frontends.quick_frontend import quick_chat |
29 from sat_frontends.quick_frontend.constants import Const as C | 30 from sat_frontends.quick_frontend.constants import Const as C |
216 # widgets | 217 # widgets |
217 self.selected_widget = None # widget currently selected (must be filled by frontend) | 218 self.selected_widget = None # widget currently selected (must be filled by frontend) |
218 | 219 |
219 # listeners | 220 # listeners |
220 self._listeners = {} # key: listener type ("avatar", "selected", etc), value: list of callbacks | 221 self._listeners = {} # key: listener type ("avatar", "selected", etc), value: list of callbacks |
222 | |
223 # triggers | |
224 self.trigger = TriggerManager() # trigger are used to change the default behaviour | |
221 | 225 |
222 ## bridge ## | 226 ## bridge ## |
223 try: | 227 try: |
224 self.bridge = create_bridge() | 228 self.bridge = create_bridge() |
225 except exceptions.BridgeExceptionNoService: | 229 except exceptions.BridgeExceptionNoService: |
451 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True) | 455 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True) |
452 | 456 |
453 def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile): | 457 def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile): |
454 from_jid = jid.JID(from_jid_s) | 458 from_jid = jid.JID(from_jid_s) |
455 to_jid = jid.JID(to_jid_s) | 459 to_jid = jid.JID(to_jid_s) |
460 | |
461 if not self.trigger.point("newMessageTrigger", from_jid, msg, type_, to_jid, extra, profile=profile): | |
462 return | |
463 | |
456 from_me = from_jid.bare == self.profiles[profile].whoami.bare | 464 from_me = from_jid.bare == self.profiles[profile].whoami.bare |
457 target = to_jid if from_me else from_jid | 465 target = to_jid if from_me else from_jid |
458 | 466 |
459 chat_type = C.CHAT_GROUP if type_ == C.MESS_TYPE_GROUPCHAT else C.CHAT_ONE2ONE | 467 chat_type = C.CHAT_GROUP if type_ == C.MESS_TYPE_GROUPCHAT else C.CHAT_ONE2ONE |
460 contact_list = self.contact_lists[profile] | 468 contact_list = self.contact_lists[profile] |
484 def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, callback=None, errback=None, profile_key=C.PROF_KEY_NONE): | 492 def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, callback=None, errback=None, profile_key=C.PROF_KEY_NONE): |
485 if callback is None: | 493 if callback is None: |
486 callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback without arg with json proxy | 494 callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback without arg with json proxy |
487 if errback is None: | 495 if errback is None: |
488 errback = lambda failure: self.showDialog(failure.fullname, failure.message, "error") | 496 errback = lambda failure: self.showDialog(failure.fullname, failure.message, "error") |
489 self.bridge.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) | 497 |
498 if not self.trigger.point("sendMessageTrigger", to_jid, message, subject, mess_type, extra, callback, errback, profile_key=profile_key): | |
499 return | |
500 | |
501 self.bridge.sendMessage(unicode(to_jid), message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) | |
490 | 502 |
491 def newAlertHandler(self, msg, title, alert_type, profile): | 503 def newAlertHandler(self, msg, title, alert_type, profile): |
492 assert alert_type in ['INFO', 'ERROR'] | 504 assert alert_type in ['INFO', 'ERROR'] |
493 self.showDialog(unicode(msg), unicode(title), alert_type.lower()) | 505 self.showDialog(unicode(msg), unicode(title), alert_type.lower()) |
494 | 506 |