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):
log.debug('_connection_lost')
self.disconnect(on_purpose = False)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline'))
self.dispatch('CONNECTION_LOST',
(_('Connection with account "%s" has been lost') % self.name,
_('Reconnect manually.')))
gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
title=_('Connection with account "%s" has been lost') % self.name,
msg=_('Reconnect manually.')))
def _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
if not self.retrycount and self.connected != 0:
self.disconnect(on_purpose = True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline'))
pritxt = _('Could not connect to "%s"') % self._hostname
sectxt = _('Check your connection or try again later.')
if self.streamError:
@ -1180,17 +1176,16 @@ class Connection(CommonConnection, ConnectionHandlers):
self.dispatch('ERROR', (pritxt, '%s\n%s' % (sectxt2, sectxt)))
return
# 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):
log.error('Connection to proxy failed: %s' % reason)
self.time_to_reconnect = None
self.on_connect_failure = None
self.disconnect(on_purpose = True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline'))
self.dispatch('CONNECTION_LOST',
(_('Connection to proxy failed'), reason))
gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
title=_('Connection to proxy failed'), msg=reason))
def _connect_success(self, con, con_type):
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):
if not con or not con.Connection:
self.disconnect(on_purpose=True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline'))
self.dispatch('CONNECTION_LOST',
(_('Could not connect to account %s') % self.name,
_('Connection with account %s has been lost. Retry connecting.') % \
self.name))
gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
title=_('Could not connect to account %s') % self.name,
msg=_('Connection with account %s has been lost. Retry '
'connecting.') % self.name))
return
self.hosts = []
self.connection_auto_accepted = False
@ -1279,12 +1272,10 @@ class Connection(CommonConnection, ConnectionHandlers):
def ssl_certificate_accepted(self):
if not self.connection:
self.disconnect(on_purpose=True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline'))
self.dispatch('CONNECTION_LOST',
(_('Could not connect to account %s') % self.name,
_('Connection with account %s has been lost. Retry connecting.') % \
self.name))
gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
title=_('Could not connect to account %s') % self.name,
msg=_('Connection with account %s has been lost. Retry '
'connecting.') % self.name))
return
name = gajim.config.get_per('accounts', self.name, 'name')
self._register_handlers(self.connection, 'ssl')
@ -1302,11 +1293,9 @@ class Connection(CommonConnection, ConnectionHandlers):
def __on_auth(self, con, auth):
if not con:
self.disconnect(on_purpose=True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline'))
self.dispatch('CONNECTION_LOST',
(_('Could not connect to "%s"') % self._hostname,
_('Check your connection or try again later')))
gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
title=_('Could not connect to "%s"') % self._hostname,
msg=_('Check your connection or try again later')))
if self.on_connect_auth:
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.keyID = gajim.config.get_per('accounts', account, 'keyid')
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:
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])
path = gtkgui_helpers.get_icon_path('gajim-connection_lost', 48)
account = obj.conn.name
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):
gajim.block_signed_in_notifications[account] = False
@ -1753,7 +1754,6 @@ class Interface:
'GC_NOTIFY': [self.handle_event_gc_notify],
'GC_SUBJECT': [self.handle_event_gc_subject],
'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_ERROR': [self.handle_event_file_request_error],
'FILE_SEND_ERROR': [self.handle_event_file_send_error],
@ -1789,6 +1789,7 @@ class Interface:
'CAPS_RECEIVED': [self.handle_event_caps_received],
'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase],
'bookmarks-received': [self.handle_event_bookmarks],
'connection-lost': [self.handle_event_connection_lost],
'gc-invitation-received': [self.handle_event_gc_invitation],
'gc-presence-received': [self.handle_event_gc_presence],
'gmail-notify': [self.handle_event_gmail_notify],