Mercurial > libervia-backend
changeset 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 | 35f99c90b736 |
children | a39d2db03c80 |
files | frontends/src/quick_frontend/quick_app.py src/tools/misc.py |
diffstat | 2 files changed, 21 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py Tue Mar 03 06:00:23 2015 +0100 +++ b/frontends/src/quick_frontend/quick_app.py Tue Mar 03 15:05:10 2015 +0100 @@ -22,6 +22,7 @@ from sat.core.i18n import _ from sat.core import exceptions +from sat.tools.misc import TriggerManager from sat_frontends.tools import jid from sat_frontends.quick_frontend.quick_widgets import QuickWidgetsManager @@ -219,6 +220,9 @@ # listeners self._listeners = {} # key: listener type ("avatar", "selected", etc), value: list of callbacks + # triggers + self.trigger = TriggerManager() # trigger are used to change the default behaviour + ## bridge ## try: self.bridge = create_bridge() @@ -453,6 +457,10 @@ def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile): from_jid = jid.JID(from_jid_s) to_jid = jid.JID(to_jid_s) + + if not self.trigger.point("newMessageTrigger", from_jid, msg, type_, to_jid, extra, profile=profile): + return + from_me = from_jid.bare == self.profiles[profile].whoami.bare target = to_jid if from_me else from_jid @@ -486,7 +494,11 @@ callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback without arg with json proxy if errback is None: errback = lambda failure: self.showDialog(failure.fullname, failure.message, "error") - self.bridge.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) + + if not self.trigger.point("sendMessageTrigger", to_jid, message, subject, mess_type, extra, callback, errback, profile_key=profile_key): + return + + self.bridge.sendMessage(unicode(to_jid), message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) def newAlertHandler(self, msg, title, alert_type, profile): assert alert_type in ['INFO', 'ERROR']
--- a/src/tools/misc.py Tue Mar 03 06:00:23 2015 +0100 +++ b/src/tools/misc.py Tue Mar 03 15:05:10 2015 +0100 @@ -20,7 +20,6 @@ """Misc usefull classes""" from sat.core.i18n import _ -import sys from sat.core.log import getLogger log = getLogger(__name__) @@ -39,8 +38,13 @@ """This class manage triggers: code which interact to change the behaviour of SàT""" - MIN_PRIORITY = float('-inf') - MAX_PRIORITY = float('+inf') + try: # FIXME: to be removed when a better solution is found + MIN_PRIORITY = float('-inf') + MAX_PRIORITY = float('+inf') + except: # XXX: Pyjamas will bug if you specify ValueError here + # Pyjamas uses the JS Float class + MIN_PRIORITY = Number.NEGATIVE_INFINITY + MAX_PRIORITY = Number.POSITIVE_INFINITY def __init__(self): self.__triggers = {} @@ -81,7 +85,7 @@ if point_name not in self.__triggers: return True - for priority,trigger in self.__triggers[point_name]: + for priority, trigger in self.__triggers[point_name]: try: if not trigger(*args, **kwargs): return False