diff frontends/src/quick_frontend/quick_app.py @ 1489:039d96e131be

frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present): - actionManager is used by default (no callback provided) - in XMLUI, the dialog is closed before calling actionManager - if keys are not managed in resuling data, an exceptions is raised
author Goffi <goffi@goffi.org>
date Tue, 25 Aug 2015 14:41:42 +0200
parents 621b045cd284
children 955221487a3e
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Tue Aug 25 14:22:21 2015 +0200
+++ b/frontends/src/quick_frontend/quick_app.py	Tue Aug 25 14:41:42 2015 +0200
@@ -465,7 +465,7 @@
         self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile)
 
     def actionNewHandler(self, action_data, id_, profile):
-        self._actionManager(action_data, profile=profile)
+        self.actionManager(action_data, profile=profile)
 
     def newContactHandler(self, jid_s, attributes, groups, profile):
         entity = jid.JID(jid_s)
@@ -714,26 +714,28 @@
     def actionResultHandler(self, type, id, data, profile):
         raise NotImplementedError
 
-    def _actionManagerUnknownError(self):
-        raise NotImplementedError
-
-
-    def _actionManager(self, action_data, callback=None, profile=C.PROF_KEY_NONE):
-        if "xmlui" in action_data:
-            ui = self.xmlui.create(self, xml_data=action_data['xmlui'], callback=callback, profile=profile)
+    def actionManager(self, action_data, callback=None, profile=C.PROF_KEY_NONE):
+        try:
+            xmlui = action_data.pop('xmlui')
+        except KeyError:
+            pass
+        else:
+            ui = self.xmlui.create(self, xml_data=xmlui, callback=callback, profile=profile)
             ui.show()
-        else:
-            self._actionManagerUnknownError()
+        if action_data:
+            raise exceptions.DataError(u"Not all keys in action_data are managed ({keys})".format(keys=', '.join(action_data.keys())))
 
     def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE):
         """ Launch a dynamic action
 
         @param callback_id: id of the action to launch
         @param data: data needed only for certain actions
-        @param callback: if not None and 'validated' key is present, it will be called with the following parameters:
-            - callback_id
-            - data
-            - profile
+        @param callback(callable, None): will be called with the resut
+            if None, self.actionManager will be called
+            else the callable will be called with the following kw parameters:
+                - data: action_data
+                - cb_id: callback id
+                - profile: %(doc_profile)s
         @param profile: %(doc_profile)s
 
         """
@@ -741,14 +743,10 @@
             data = dict()
 
         def action_cb(data):
-            if not data:
-                # action was a one shot, nothing to do
-                pass
-            elif 'validated' in data:
-                if callback:
-                    callback(callback_id, data, profile)
+            if callback is None:
+                self.actionManager(data, profile=profile)
             else:
-                self._actionManager(data, profile=profile)
+                callback(data=data, cb_id=callback_id, profile=profile)
 
         self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure)