diff frontends/src/quick_frontend/quick_app.py @ 1060:aa15453ec54d

core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
author souliane <souliane@mailoo.org>
date Fri, 23 May 2014 09:59:35 +0200
parents 0a9986452bba
children 6ec513ad92c2
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Fri May 23 10:40:54 2014 +0200
+++ b/frontends/src/quick_frontend/quick_app.py	Fri May 23 09:59:35 2014 +0200
@@ -49,7 +49,6 @@
             sys.exit(1)
         self.bridge.register("connected", self.connected)
         self.bridge.register("disconnected", self.disconnected)
-        self.bridge.register("connectionError", self.connectionError)
         self.bridge.register("newContact", self.newContact)
         self.bridge.register("newMessage", self._newMessage)
         self.bridge.register("newAlert", self.newAlert)
@@ -152,10 +151,19 @@
         self.bridge.asyncGetParamA("Watched", "Misc", profile_key=profile,
                                    callback=lambda watched: self.plug_profile_4(watched, autoconnect, profile), errback=self._getParamError)
 
+    def asyncConnect(self, profile, callback=None, errback=None):
+        if not callback:
+            callback = lambda dummy: None
+        if not errback:
+            def errback(failure):
+                log.error(_(u"Can't connect profile [%s]") % failure)
+                self.launchAction(C.CHANGE_XMPP_PASSWD_ID, {}, profile_key=profile)
+        self.bridge.asyncConnect(profile, callback=callback, errback=errback)
+
     def plug_profile_4(self, watched, autoconnect, profile):
         if autoconnect and not self.bridge.isConnected(profile):
             #Does the user want autoconnection ?
-            self.bridge.asyncConnect(profile, callback=lambda dummy: self.plug_profile_5(watched, autoconnect, profile), errback=lambda ignore: log.error(_('Error during autoconnection')))
+            self.asyncConnect(profile, callback=lambda dummy: self.plug_profile_5(watched, autoconnect, profile))
         else:
             self.plug_profile_5(watched, autoconnect, profile)
 
@@ -229,17 +237,6 @@
         self.contact_list.clearContacts()
         self.setStatusOnline(False)
 
-    def connectionError(self, error_type, profile):
-        """called when something goes wrong with the connection"""
-        if not self.check_profile(profile):
-            return
-        log.debug(_("Connection Error"))
-        self.disconnected(profile)
-        if error_type == "AUTH_ERROR":
-            self.launchAction(C.CHANGE_XMPP_PASSWD_ID, {}, profile_key=profile)
-        else:
-            log.error(_('FIXME: error_type %s not implemented') % error_type)
-
     def newContact(self, JabberId, attributes, groups, profile):
         if not self.check_profile(profile):
             return
@@ -612,6 +609,15 @@
     def actionResult(self, type, id, data):
         raise NotImplementedError
 
+    def launchAction(self, callback_id, data=None, profile_key="@NONE@"):
+        """ Launch a dynamic action
+        @param callback_id: id of the action to launch
+        @param data: data needed only for certain actions
+        @param profile_key: %(doc_profile_key)s
+
+        """
+        raise NotImplementedError
+
     def onExit(self):
         """Must be called when the frontend is terminating"""
         #TODO: mange multi-profile here