use NEC to handle new account connected events
This commit is contained in:
parent
60e8c63a29
commit
d676dbd900
3 changed files with 61 additions and 45 deletions
|
@ -872,30 +872,17 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
self._hostname, self.new_account_form,
|
||||
_on_register_result)
|
||||
return
|
||||
try:
|
||||
errnum = self.connection.Connection.ssl_errnum
|
||||
except AttributeError:
|
||||
errnum = -1 # we don't have an errnum
|
||||
ssl_msg = ''
|
||||
if errnum > 0:
|
||||
ssl_msg = ssl_error.get(errnum, _('Unknown SSL error: %d') % errnum)
|
||||
ssl_cert = ''
|
||||
if hasattr(self.connection.Connection, 'ssl_cert_pem'):
|
||||
ssl_cert = self.connection.Connection.ssl_cert_pem
|
||||
ssl_fingerprint = ''
|
||||
if hasattr(self.connection.Connection, 'ssl_fingerprint_sha1'):
|
||||
ssl_fingerprint = \
|
||||
self.connection.Connection.ssl_fingerprint_sha1
|
||||
self.dispatch('NEW_ACC_CONNECTED', (conf, is_form, ssl_msg,
|
||||
errnum, ssl_cert, ssl_fingerprint))
|
||||
gajim.nec.push_incoming_event(NewAccountConnectedEvent(None,
|
||||
conn=self, config=conf, is_form=is_form))
|
||||
self.connection.UnregisterDisconnectHandler(
|
||||
self._on_new_account)
|
||||
self.disconnect(on_purpose=True)
|
||||
return
|
||||
if not data[1]: # wrong answer
|
||||
self.dispatch('ERROR', (_('Invalid answer'),
|
||||
_('Transport %(name)s answered wrongly to register request: '
|
||||
'%(error)s') % {'name': data[0], 'error': data[3]}))
|
||||
_('Transport %(name)s answered wrongly to register '
|
||||
'request: %(error)s') % {'name': data[0],
|
||||
'error': data[3]}))
|
||||
return
|
||||
is_form = data[2]
|
||||
conf = data[1]
|
||||
|
@ -1810,8 +1797,9 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
if len(self._connection_types) or len(self._hosts):
|
||||
# There are still other way to try to connect
|
||||
return
|
||||
self.dispatch('NEW_ACC_NOT_CONNECTED',
|
||||
(_('Could not connect to "%s"') % self._hostname))
|
||||
reason = _('Could not connect to "%s"') % self._hostname
|
||||
gajim.nec.push_incoming_event(NewAccountNotConnectedEvent(None,
|
||||
conn=self, reason=reason))
|
||||
return
|
||||
self.on_connect_failure = None
|
||||
self.connection = con
|
||||
|
|
|
@ -1241,3 +1241,30 @@ class AccountCreatedEvent(nec.NetworkIncomingEvent):
|
|||
class AccountNotCreatedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'account-not-created'
|
||||
base_network_events = []
|
||||
|
||||
class NewAccountConnectedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'new-account-connected'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
try:
|
||||
self.errnum = self.conn.connection.Connection.ssl_errnum
|
||||
except AttributeError:
|
||||
self.errnum = -1 # we don't have an errnum
|
||||
self.ssl_msg = ''
|
||||
if self.errnum > 0:
|
||||
from common.connection import ssl_error
|
||||
self.ssl_msg = ssl_error.get(errnum, _('Unknown SSL error: %d') % \
|
||||
errnum)
|
||||
self.ssl_cert = ''
|
||||
if hasattr(self.conn.connection.Connection, 'ssl_cert_pem'):
|
||||
self.ssl_cert = self.conn.connection.Connection.ssl_cert_pem
|
||||
self.ssl_fingerprint = ''
|
||||
if hasattr(self.conn.connection.Connection, 'ssl_fingerprint_sha1'):
|
||||
self.ssl_fingerprint = \
|
||||
self.conn.connection.Connection.ssl_fingerprint_sha1
|
||||
return True
|
||||
|
||||
class NewAccountNotConnectedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'new-account-not-connected'
|
||||
base_network_events = []
|
|
@ -3443,10 +3443,10 @@ class AccountCreationWizardWindow:
|
|||
self.notebook.set_current_page(0)
|
||||
self.xml.connect_signals(self)
|
||||
self.window.show_all()
|
||||
gajim.ged.register_event_handler('NEW_ACC_CONNECTED', ged.CORE,
|
||||
self.new_acc_connected)
|
||||
gajim.ged.register_event_handler('NEW_ACC_NOT_CONNECTED', ged.CORE,
|
||||
self.new_acc_not_connected)
|
||||
gajim.ged.register_event_handler('new-account-connected', ged.GUI1,
|
||||
self._nec_new_acc_connected)
|
||||
gajim.ged.register_event_handler('new-account-not-connected', ged.GUI1,
|
||||
self._nec_new_acc_not_connected)
|
||||
gajim.ged.register_event_handler('account-created', ged.GUI1,
|
||||
self._nec_acc_is_ok)
|
||||
gajim.ged.register_event_handler('account-not-created', ged.GUI1,
|
||||
|
@ -3460,10 +3460,10 @@ class AccountCreationWizardWindow:
|
|||
del gajim.connections[self.account]
|
||||
if self.account in gajim.config.get_per('accounts'):
|
||||
gajim.config.del_per('accounts', self.account)
|
||||
gajim.ged.remove_event_handler('NEW_ACC_CONNECTED', ged.CORE,
|
||||
self.new_acc_connected)
|
||||
gajim.ged.remove_event_handler('NEW_ACC_NOT_CONNECTED', ged.CORE,
|
||||
self.new_acc_not_connected)
|
||||
gajim.ged.remove_event_handler('new-account-connected', ged.GUI1,
|
||||
self._nec_new_acc_connected)
|
||||
gajim.ged.remove_event_handler('new-account-not-connected', ged.GUI1,
|
||||
self._nec_new_acc_not_connected)
|
||||
gajim.ged.remove_event_handler('account-created', ged.GUI1,
|
||||
self._nec_acc_is_ok)
|
||||
gajim.ged.remove_event_handler('account-not-created', ged.GUI1,
|
||||
|
@ -3706,41 +3706,42 @@ class AccountCreationWizardWindow:
|
|||
self.progressbar.pulse()
|
||||
return True # loop forever
|
||||
|
||||
def new_acc_connected(self, account, array):
|
||||
def _nec_new_acc_connected(self, obj):
|
||||
"""
|
||||
Connection to server succeded, present the form to the user
|
||||
"""
|
||||
# We receive events from all accounts from GED
|
||||
if account != self.account:
|
||||
if obj.conn.name != self.account:
|
||||
return
|
||||
form, is_form, ssl_msg, ssl_err, ssl_cert, ssl_fingerprint = array
|
||||
if self.update_progressbar_timeout_id is not None:
|
||||
gobject.source_remove(self.update_progressbar_timeout_id)
|
||||
self.back_button.show()
|
||||
self.forward_button.show()
|
||||
self.is_form = is_form
|
||||
if is_form:
|
||||
dataform = dataforms.ExtendForm(node = form)
|
||||
self.is_form = obj.is_form
|
||||
if obj.is_form:
|
||||
dataform = dataforms.ExtendForm(node=obj.config)
|
||||
self.data_form_widget = dataforms_widget.DataFormWidget(dataform)
|
||||
else:
|
||||
self.data_form_widget = FakeDataForm(form)
|
||||
self.data_form_widget = FakeDataForm(obj.config)
|
||||
self.data_form_widget.show_all()
|
||||
self.xml.get_object('form_vbox').pack_start(self.data_form_widget)
|
||||
self.ssl_fingerprint = ssl_fingerprint
|
||||
self.ssl_cert = ssl_cert
|
||||
if ssl_msg:
|
||||
self.ssl_fingerprint = obj.ssl_fingerprint
|
||||
self.ssl_cert = obj.ssl_cert
|
||||
if obj.ssl_msg:
|
||||
# An SSL warning occured, show it
|
||||
hostname = gajim.connections[self.account].new_account_info['hostname']
|
||||
hostname = gajim.connections[self.account].new_account_info[
|
||||
'hostname']
|
||||
self.xml.get_object('ssl_label').set_markup(_(
|
||||
'<b>Security Warning</b>'
|
||||
'\n\nThe authenticity of the %(hostname)s SSL certificate could'
|
||||
' be invalid.\nSSL Error: %(error)s\n'
|
||||
'Do you still want to connect to this server?') % {
|
||||
'hostname': hostname, 'error': ssl_msg})
|
||||
if ssl_err in (18, 27):
|
||||
'hostname': hostname, 'error': obj.ssl_msg})
|
||||
if obj.ssl_err in (18, 27):
|
||||
text = _('Add this certificate to the list of trusted '
|
||||
'certificates.\nSHA1 fingerprint of the certificate:\n%s') \
|
||||
% ssl_fingerprint
|
||||
% obj.ssl_fingerprint
|
||||
self.xml.get_object('ssl_checkbutton').set_label(text)
|
||||
else:
|
||||
self.xml.get_object('ssl_checkbutton').set_no_show_all(True)
|
||||
|
@ -3749,12 +3750,12 @@ class AccountCreationWizardWindow:
|
|||
else:
|
||||
self.notebook.set_current_page(4) # show form page
|
||||
|
||||
def new_acc_not_connected(self, account, reason):
|
||||
def _nec_new_acc_not_connected(self, obj):
|
||||
"""
|
||||
Account creation failed: connection to server failed
|
||||
"""
|
||||
# We receive events from all accounts from GED
|
||||
if account != self.account:
|
||||
if obj.conn.name != self.account:
|
||||
return
|
||||
if self.account not in gajim.connections:
|
||||
return
|
||||
|
@ -3770,7 +3771,7 @@ class AccountCreationWizardWindow:
|
|||
img = self.xml.get_object('finish_image')
|
||||
img.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG)
|
||||
finish_text = '<big><b>%s</b></big>\n\n%s' % (
|
||||
_('An error occurred during account creation'), reason)
|
||||
_('An error occurred during account creation'), obj.reason)
|
||||
self.finish_label.set_markup(finish_text)
|
||||
self.notebook.set_current_page(6) # show finish page
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue