From 244a33d2c77764d87130a99586590742d169f775 Mon Sep 17 00:00:00 2001 From: souliane Date: Fri, 23 May 2014 09:59:35 +0200 Subject: [PATCH] core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal --- frontends/src/primitivus/primitivus | 2 +- frontends/src/primitivus/status.py | 2 +- frontends/src/quick_frontend/quick_app.py | 32 +++++++++++-------- frontends/src/wix/main_window.py | 2 +- src/bridge/DBus.py | 8 ----- .../bridge_constructor/bridge_template.ini | 9 ------ src/core/xmpp.py | 14 ++++---- src/stdui/ui_profile_manager.py | 4 ++- 8 files changed, 32 insertions(+), 41 deletions(-) diff --git a/frontends/src/primitivus/primitivus b/frontends/src/primitivus/primitivus index 0bb5acef..c72732a0 100755 --- a/frontends/src/primitivus/primitivus +++ b/frontends/src/primitivus/primitivus @@ -561,7 +561,7 @@ class PrimitivusApp(QuickApp, InputHistory): #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) diff --git a/frontends/src/primitivus/status.py b/frontends/src/primitivus/status.py index 0f3b4fda..fb138266 100644 --- a/frontends/src/primitivus/status.py +++ b/frontends/src/primitivus/status.py @@ -34,7 +34,7 @@ class StatusBar(urwid.Columns): 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) diff --git a/frontends/src/quick_frontend/quick_app.py b/frontends/src/quick_frontend/quick_app.py index 08e38630..75a84838 100644 --- a/frontends/src/quick_frontend/quick_app.py +++ b/frontends/src/quick_frontend/quick_app.py @@ -49,7 +49,6 @@ class QuickApp(object): 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 @@ class QuickApp(object): 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 @@ class QuickApp(object): 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 @@ class QuickApp(object): 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 diff --git a/frontends/src/wix/main_window.py b/frontends/src/wix/main_window.py index 3a6e1153..6b30dce8 100644 --- a/frontends/src/wix/main_window.py +++ b/frontends/src/wix/main_window.py @@ -391,7 +391,7 @@ class MainWindow(wx.Frame, QuickApp): 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) diff --git a/src/bridge/DBus.py b/src/bridge/DBus.py index 8c017aca..4c7c757c 100755 --- a/src/bridge/DBus.py +++ b/src/bridge/DBus.py @@ -135,11 +135,6 @@ class DbusObject(dbus.service.Object): def connected(self, profile): pass - @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): @@ -547,9 +542,6 @@ class DBusBridge(Bridge): 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) diff --git a/src/bridge/bridge_constructor/bridge_template.ini b/src/bridge/bridge_constructor/bridge_template.ini index ad13720c..8cb31821 100644 --- a/src/bridge/bridge_constructor/bridge_template.ini +++ b/src/bridge/bridge_constructor/bridge_template.ini @@ -19,15 +19,6 @@ sig_in=s 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 diff --git a/src/core/xmpp.py b/src/core/xmpp.py index e8384814..0d9b3e55 100644 --- a/src/core/xmpp.py +++ b/src/core/xmpp.py @@ -83,26 +83,26 @@ class SatXMPPClient(client.XMPPClient): 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): diff --git a/src/stdui/ui_profile_manager.py b/src/stdui/ui_profile_manager.py index 6027c3f7..2bf2a325 100644 --- a/src/stdui/ui_profile_manager.py +++ b/src/stdui/ui_profile_manager.py @@ -129,4 +129,6 @@ class ProfileManager(object): 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