quick_frontend: fixes an issue with the profile in the signal handler

This commit is contained in:
souliane 2014-08-21 22:46:57 +02:00
commit 162b310cd7

View file

@ -21,9 +21,9 @@ from sat.core.i18n import _
import sys
from sat.core.log import getLogger
log = getLogger(__name__)
from sat.tools.jid import JID
from sat.tools.jid import JID
from sat_frontends.bridge.DBus import DBusBridgeFrontend
from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError
from sat.core import exceptions
from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
from optparse import OptionParser
@ -41,10 +41,10 @@ class QuickApp(object):
## bridge ##
try:
self.bridge = DBusBridgeFrontend()
except BridgeExceptionNoService:
except exceptions.BridgeExceptionNoService:
print(_(u"Can't connect to SàT backend, are you sure it's launched ?"))
sys.exit(1)
except BridgeInitError:
except exceptions.BridgeInitError:
print(_(u"Can't init bridge"))
sys.exit(1)
self.registerSignal("connected")
@ -88,20 +88,28 @@ class QuickApp(object):
self.current_action_ids_cb = {}
self.media_dir = self.bridge.getConfig('', 'media_dir')
def registerSignal(self, functionName, handler=None, iface="core"):
def registerSignal(self, functionName, handler=None, iface="core", with_profile=True):
"""Register a handler for a signal
@param functionName: name of the signal to handle
@param handler: method to call when the signal arrive, None for calling an automaticaly named handler (functionName + 'Handler')
@param iface: interface of the bridge to use
@param functionName (str): name of the signal to handle
@param handler (instancemethod): method to call when the signal arrive, None for calling an automatically named handler (functionName + 'Handler')
@param iface (str): interface of the bridge to use ('core' or 'plugin')
@param with_profile (boolean): True if the signal concerns a specific profile, in that case the profile name has to be passed by the caller
"""
if handler is None:
handler = getattr(self, "%s%s" % (functionName, 'Handler'))
if not with_profile:
self.bridge.register(functionName, handler, iface)
return
def signalReceived(*args, **kwargs):
profile = kwargs.get('profile', None)
profile = kwargs.get('profile')
if profile is None:
if not args:
raise exceptions.ProfileNotSetError
profile = args[-1]
if profile is not None and not self.check_profile(profile):
return # we ignore signal for profiles we don't manage
return # we ignore signal for profiles we don't manage
handler(*args, **kwargs)
self.bridge.register(functionName, signalReceived, iface)
@ -565,7 +573,7 @@ class QuickApp(object):
def askConfirmationHandler(self, confirm_id, confirm_type, data, profile):
raise NotImplementedError
def actionResultHandler(self, type, id, data):
def actionResultHandler(self, type, id, data, profile):
raise NotImplementedError
def launchAction(self, callback_id, data=None, profile_key="@NONE@"):