core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
This commit is contained in:
parent
f719875f0b
commit
244a33d2c7
8 changed files with 32 additions and 41 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue