diff frontends/src/quick_frontend/quick_app.py @ 1468:731fbed0b9cf

quick_frontend, primitivus: handling of actionNew signal
author Goffi <goffi@goffi.org>
date Tue, 18 Aug 2015 09:01:18 +0200
parents 9fce331ba0fd
children 621b045cd284
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Tue Aug 18 09:01:18 2015 +0200
+++ b/frontends/src/quick_frontend/quick_app.py	Tue Aug 18 09:01:18 2015 +0200
@@ -199,12 +199,14 @@
     """This class contain the main methods needed for the frontend"""
     MB_HANDLE = True # Set to false if the frontend doesn't manage microblog
 
-    def __init__(self, create_bridge, check_options=None):
+    def __init__(self, create_bridge, xmlui, check_options=None):
         """Create a frontend application
 
         @param create_bridge: method to use to create the Bridge
+        @param xmlui: xmlui module
         @param check_options: method to call to check options (usually command line arguments)
         """
+        self.xmlui = xmlui
         self.menus = quick_menus.QuickMenusManager(self)
         ProfileManager.host = self
         self.profiles = ProfilesManager()
@@ -238,6 +240,7 @@
         ProfileManager.bridge = self.bridge
         self.registerSignal("connected")
         self.registerSignal("disconnected")
+        self.registerSignal("actionNew")
         self.registerSignal("newContact")
         self.registerSignal("newMessage")
         self.registerSignal("newAlert")
@@ -463,6 +466,9 @@
         self.contact_lists[profile].clearContacts()
         self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile)
 
+    def actionNewHandler(self, action_data, id_, profile):
+        self._actionManager(action_data, profile=profile)
+
     def newContactHandler(self, jid_s, attributes, groups, profile):
         entity = jid.JID(jid_s)
         _groups = list(groups)
@@ -672,6 +678,9 @@
     def showAlert(self, message):
         pass  #FIXME
 
+    def dialogFailure(self, failure):
+        log.warning(u"Failure: {}".format(failure))
+
     def updateAlertsCounter(self):
         """Update the over whole alerts counter
 
@@ -713,18 +722,43 @@
     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)
+            ui.show()
+        else:
+            self._actionManagerUnknownError()
+
     def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE):
-        """Launch a dynamic action
+        """ 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_key
-        @param profile_key: %(doc_profile)s
+            - profile
+        @param profile: %(doc_profile)s
 
         """
-        raise NotImplementedError
+        if data is None:
+            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)
+            else:
+                self._actionManager(data, profile=profile)
+
+        self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure)
 
     def disconnect(self, profile):
         log.info("disconnecting")