changeset 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 b2b9c184033f
children 3700165d68dc
files frontends/src/primitivus/primitivus frontends/src/primitivus/status.py frontends/src/quick_frontend/quick_app.py frontends/src/wix/main_window.py src/bridge/DBus.py src/bridge/bridge_constructor/bridge_template.ini src/core/xmpp.py src/stdui/ui_profile_manager.py
diffstat 8 files changed, 32 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus	Fri May 23 10:40:54 2014 +0200
+++ b/frontends/src/primitivus/primitivus	Fri May 23 09:59:35 2014 +0200
@@ -561,7 +561,7 @@
 
     #MENU EVENTS#
     def onConnectRequest(self, menu):
-        self.bridge.asyncConnect(self.profile, callback=lambda dummy: None)
+        QuickApp.asyncConnect(self, self.profile)
 
     def onDisconnectRequest(self, menu):
         self.bridge.disconnect(self.profile)
--- a/frontends/src/primitivus/status.py	Fri May 23 10:40:54 2014 +0200
+++ b/frontends/src/primitivus/status.py	Fri May 23 09:59:35 2014 +0200
@@ -34,7 +34,7 @@
         status_prefix = urwid.Text('[')
         status_suffix = urwid.Text(']')
         self.status = sat_widgets.ClickableText('')
-        self.setPresenceStatus('', '')
+        self.setPresenceStatus('unavailable', '')
         urwid.Columns.__init__(self, [('weight', 1, self.presence), ('weight', 1, status_prefix),
                                       ('weight', 9, self.status), ('weight', 1, status_suffix)])
         urwid.connect_signal(self.presence, 'click', self.onPresenceClick)
--- 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
--- a/frontends/src/wix/main_window.py	Fri May 23 10:40:54 2014 +0200
+++ b/frontends/src/wix/main_window.py	Fri May 23 09:59:35 2014 +0200
@@ -391,7 +391,7 @@
             self.chat_wins[jid.bare].Show()
 
     def onConnectRequest(self, e):
-        self.bridge.asyncConnect(self.profile, callback=lambda dummy: None)
+        QuickApp.asyncConnect(self, self.profile)
 
     def onDisconnectRequest(self, e):
         self.bridge.disconnect(self.profile)
--- a/src/bridge/DBus.py	Fri May 23 10:40:54 2014 +0200
+++ b/src/bridge/DBus.py	Fri May 23 09:59:35 2014 +0200
@@ -137,11 +137,6 @@
 
     @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX,
                          signature='ss')
-    def connectionError(self, error_type, profile):
-        pass
-
-    @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX,
-                         signature='ss')
     def contactDeleted(self, entity_jid, profile):
         pass
 
@@ -547,9 +542,6 @@
     def connected(self, profile):
         self.dbus_bridge.connected(profile)
 
-    def connectionError(self, error_type, profile):
-        self.dbus_bridge.connectionError(error_type, profile)
-
     def contactDeleted(self, entity_jid, profile):
         self.dbus_bridge.contactDeleted(entity_jid, profile)
 
--- a/src/bridge/bridge_constructor/bridge_template.ini	Fri May 23 10:40:54 2014 +0200
+++ b/src/bridge/bridge_constructor/bridge_template.ini	Fri May 23 09:59:35 2014 +0200
@@ -19,15 +19,6 @@
 doc=Connection is finished or lost
 doc_param_0=%(doc_profile)s
 
-[connectionError]
-type=signal
-category=core
-sig_in=ss
-doc=Something went wront with the connection
-doc_param_0=error_type: Why the connection got wrong, can be
- - AUTH_ERROR: Authentification error
-doc_param_1=%(doc_profile)s
-
 [newContact]
 type=signal
 category=core
--- a/src/core/xmpp.py	Fri May 23 10:40:54 2014 +0200
+++ b/src/core/xmpp.py	Fri May 23 09:59:35 2014 +0200
@@ -83,26 +83,26 @@
 
     def initializationFailed(self, reason):
         log.error(_("ERROR: XMPP connection failed for profile '%(profile)s': %(reason)s" % {'profile': self.profile, 'reason': reason}))
-        self.host_app.bridge.connectionError("AUTH_ERROR", self.profile)
+        self.conn_deferred.errback(reason.value)
         try:
             client.XMPPClient.initializationFailed(self, reason)
         except:
-            # we already send an error signal, no need to raise an exception
+            # we already chained an errback, no need to raise an exception
             pass
-        self.conn_deferred.errback()
 
     def isConnected(self):
         return self.__connected
 
     def connectionLost(self, connector, unused_reason):
-        self.__connected = False
-        log.info(_("********** [%s] DISCONNECTED **********") % self.profile)
         try:
             self.keep_alife.stop()
         except AttributeError:
             log.debug(_("No keep_alife"))
-        self.host_app.bridge.disconnected(self.profile)  # we send the signal to the clients
-        self.host_app.purgeClient(self.profile)  # and we remove references to this client
+        if self.__connected:
+            log.info(_("********** [%s] DISCONNECTED **********") % self.profile)
+            self.host_app.bridge.disconnected(self.profile)  # we send the signal to the clients
+            self.host_app.purgeClient(self.profile)  # and we remove references to this client
+        self.__connected = False
 
 
 class SatMessageProtocol(xmppim.MessageProtocol):
--- a/src/stdui/ui_profile_manager.py	Fri May 23 10:40:54 2014 +0200
+++ b/src/stdui/ui_profile_manager.py	Fri May 23 09:59:35 2014 +0200
@@ -129,4 +129,6 @@
         xmpp_password = data[xml_tools.formEscape('xmpp_password')]
         d = self.host.memory.setParam("Password", xmpp_password, "Connection", profile_key=profile)
         d.addCallback(lambda dummy: self.host.asyncConnect(profile))
-        return {}
+        d.addCallback(lambda dummy: {})
+        d.addErrback(lambda dummy: self._changeXMPPPassword({}, profile))
+        return d