use NEC to handle connection lost events

This commit is contained in:
Yann Leboulanger 2010-11-15 17:03:38 +01:00
parent da97249ef6
commit 9d21a70896
3 changed files with 31 additions and 32 deletions

View File

@ -812,11 +812,9 @@ class Connection(CommonConnection, ConnectionHandlers):
def _connection_lost(self): def _connection_lost(self):
log.debug('_connection_lost') log.debug('_connection_lost')
self.disconnect(on_purpose = False) self.disconnect(on_purpose = False)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self, gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
show='offline')) title=_('Connection with account "%s" has been lost') % self.name,
self.dispatch('CONNECTION_LOST', msg=_('Reconnect manually.')))
(_('Connection with account "%s" has been lost') % self.name,
_('Reconnect manually.')))
def _event_dispatcher(self, realm, event, data): def _event_dispatcher(self, realm, event, data):
CommonConnection._event_dispatcher(self, realm, event, data) CommonConnection._event_dispatcher(self, realm, event, data)
@ -1168,8 +1166,6 @@ class Connection(CommonConnection, ConnectionHandlers):
# we are not retrying, and not conecting # we are not retrying, and not conecting
if not self.retrycount and self.connected != 0: if not self.retrycount and self.connected != 0:
self.disconnect(on_purpose = True) self.disconnect(on_purpose = True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline'))
pritxt = _('Could not connect to "%s"') % self._hostname pritxt = _('Could not connect to "%s"') % self._hostname
sectxt = _('Check your connection or try again later.') sectxt = _('Check your connection or try again later.')
if self.streamError: if self.streamError:
@ -1180,17 +1176,16 @@ class Connection(CommonConnection, ConnectionHandlers):
self.dispatch('ERROR', (pritxt, '%s\n%s' % (sectxt2, sectxt))) self.dispatch('ERROR', (pritxt, '%s\n%s' % (sectxt2, sectxt)))
return return
# show popup # show popup
self.dispatch('CONNECTION_LOST', (pritxt, sectxt)) gajim.nec.push_incoming_event(ConnectionLostEvent(None,
conn=self, title=pritxt, msg=sectxt))
def on_proxy_failure(self, reason): def on_proxy_failure(self, reason):
log.error('Connection to proxy failed: %s' % reason) log.error('Connection to proxy failed: %s' % reason)
self.time_to_reconnect = None self.time_to_reconnect = None
self.on_connect_failure = None self.on_connect_failure = None
self.disconnect(on_purpose = True) self.disconnect(on_purpose = True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self, gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
show='offline')) title=_('Connection to proxy failed'), msg=reason))
self.dispatch('CONNECTION_LOST',
(_('Connection to proxy failed'), reason))
def _connect_success(self, con, con_type): def _connect_success(self, con, con_type):
if not self.connected: # We went offline during connecting process if not self.connected: # We went offline during connecting process
@ -1219,12 +1214,10 @@ class Connection(CommonConnection, ConnectionHandlers):
def connection_accepted(self, con, con_type): def connection_accepted(self, con, con_type):
if not con or not con.Connection: if not con or not con.Connection:
self.disconnect(on_purpose=True) self.disconnect(on_purpose=True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self, gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
show='offline')) title=_('Could not connect to account %s') % self.name,
self.dispatch('CONNECTION_LOST', msg=_('Connection with account %s has been lost. Retry '
(_('Could not connect to account %s') % self.name, 'connecting.') % self.name))
_('Connection with account %s has been lost. Retry connecting.') % \
self.name))
return return
self.hosts = [] self.hosts = []
self.connection_auto_accepted = False self.connection_auto_accepted = False
@ -1279,12 +1272,10 @@ class Connection(CommonConnection, ConnectionHandlers):
def ssl_certificate_accepted(self): def ssl_certificate_accepted(self):
if not self.connection: if not self.connection:
self.disconnect(on_purpose=True) self.disconnect(on_purpose=True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self, gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
show='offline')) title=_('Could not connect to account %s') % self.name,
self.dispatch('CONNECTION_LOST', msg=_('Connection with account %s has been lost. Retry '
(_('Could not connect to account %s') % self.name, 'connecting.') % self.name))
_('Connection with account %s has been lost. Retry connecting.') % \
self.name))
return return
name = gajim.config.get_per('accounts', self.name, 'name') name = gajim.config.get_per('accounts', self.name, 'name')
self._register_handlers(self.connection, 'ssl') self._register_handlers(self.connection, 'ssl')
@ -1302,11 +1293,9 @@ class Connection(CommonConnection, ConnectionHandlers):
def __on_auth(self, con, auth): def __on_auth(self, con, auth):
if not con: if not con:
self.disconnect(on_purpose=True) self.disconnect(on_purpose=True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self, gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
show='offline')) title=_('Could not connect to "%s"') % self._hostname,
self.dispatch('CONNECTION_LOST', msg=_('Check your connection or try again later')))
(_('Could not connect to "%s"') % self._hostname,
_('Check your connection or try again later')))
if self.on_connect_auth: if self.on_connect_auth:
self.on_connect_auth(None) self.on_connect_auth(None)
self.on_connect_auth = None self.on_connect_auth = None

View File

@ -1313,3 +1313,12 @@ class BadGPGPassphraseEvent(nec.NetworkIncomingEvent):
self.use_gpg_agent = gajim.config.get('use_gpg_agent') self.use_gpg_agent = gajim.config.get('use_gpg_agent')
self.keyID = gajim.config.get_per('accounts', account, 'keyid') self.keyID = gajim.config.get_per('accounts', account, 'keyid')
return True return True
class ConnectionLostEvent(nec.NetworkIncomingEvent):
name = 'connection-lost'
base_network_events = []
def generate(self):
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self.conn,
show='offline'))
return True

View File

@ -188,11 +188,12 @@ class Interface:
if ctrl and ctrl.type_id == message_control.TYPE_GC: if ctrl and ctrl.type_id == message_control.TYPE_GC:
ctrl.print_conversation('Error %s: %s' % (obj.errcode, obj.errmsg)) ctrl.print_conversation('Error %s: %s' % (obj.errcode, obj.errmsg))
def handle_event_connection_lost(self, account, array): def handle_event_connection_lost(self, obj):
# ('CONNECTION_LOST', account, [title, text]) # ('CONNECTION_LOST', account, [title, text])
path = gtkgui_helpers.get_icon_path('gajim-connection_lost', 48) path = gtkgui_helpers.get_icon_path('gajim-connection_lost', 48)
account = obj.conn.name
notify.popup(_('Connection Failed'), account, account, notify.popup(_('Connection Failed'), account, account,
'connection_failed', path, array[0], array[1]) 'connection_failed', path, obj.title, obj.msg)
def unblock_signed_in_notifications(self, account): def unblock_signed_in_notifications(self, account):
gajim.block_signed_in_notifications[account] = False gajim.block_signed_in_notifications[account] = False
@ -1753,7 +1754,6 @@ class Interface:
'GC_NOTIFY': [self.handle_event_gc_notify], 'GC_NOTIFY': [self.handle_event_gc_notify],
'GC_SUBJECT': [self.handle_event_gc_subject], 'GC_SUBJECT': [self.handle_event_gc_subject],
'GC_CONFIG_CHANGE': [self.handle_event_gc_config_change], 'GC_CONFIG_CHANGE': [self.handle_event_gc_config_change],
'CONNECTION_LOST': [self.handle_event_connection_lost],
'FILE_REQUEST': [self.handle_event_file_request], 'FILE_REQUEST': [self.handle_event_file_request],
'FILE_REQUEST_ERROR': [self.handle_event_file_request_error], 'FILE_REQUEST_ERROR': [self.handle_event_file_request_error],
'FILE_SEND_ERROR': [self.handle_event_file_send_error], 'FILE_SEND_ERROR': [self.handle_event_file_send_error],
@ -1789,6 +1789,7 @@ class Interface:
'CAPS_RECEIVED': [self.handle_event_caps_received], 'CAPS_RECEIVED': [self.handle_event_caps_received],
'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase], 'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase],
'bookmarks-received': [self.handle_event_bookmarks], 'bookmarks-received': [self.handle_event_bookmarks],
'connection-lost': [self.handle_event_connection_lost],
'gc-invitation-received': [self.handle_event_gc_invitation], 'gc-invitation-received': [self.handle_event_gc_invitation],
'gc-presence-received': [self.handle_event_gc_presence], 'gc-presence-received': [self.handle_event_gc_presence],
'gmail-notify': [self.handle_event_gmail_notify], 'gmail-notify': [self.handle_event_gmail_notify],