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