diff frontends/src/quick_frontend/quick_app.py @ 1117:6053fb8a6466

quick_frontend: fixes an issue with the profile in the signal handler
author souliane <souliane@mailoo.org>
date Thu, 21 Aug 2014 22:46:57 +0200
parents a096b8579a3c
children 75025461141f
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Thu Aug 21 02:14:24 2014 +0200
+++ b/frontends/src/quick_frontend/quick_app.py	Thu Aug 21 22:46:57 2014 +0200
@@ -21,9 +21,9 @@
 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 @@
         ## 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 @@
         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 @@
     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@"):