handle ERROR and INFORMATION events through NEC

This commit is contained in:
Yann Leboulanger 2011-11-22 19:25:15 +01:00
parent ae6ffa2a18
commit 2582720366
9 changed files with 103 additions and 64 deletions

View File

@ -256,8 +256,9 @@ class CommonConnection:
try: try:
jid = self.check_jid(jid) jid = self.check_jid(jid)
except helpers.InvalidFormat: except helpers.InvalidFormat:
self.dispatch('ERROR', (_('Invalid Jabber ID'), gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
_('It is not possible to send a message to %s, this JID is not ' level='error', pri_txt=_('Invalid Jabber ID'), sec_txt=_(
'It is not possible to send a message to %s, this JID is not '
'valid.') % jid)) 'valid.') % jid))
return return
@ -912,9 +913,10 @@ class Connection(CommonConnection, ConnectionHandlers):
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'), gajim.nec.push_incoming_event(InformationEvent(None,
_('Transport %(name)s answered wrongly to register ' conn=self, level='error', pri_txt=_('Invalid answer'),
'request: %(error)s') % {'name': data[0], sec_txt=_('Transport %(name)s answered wrongly to '
'register request: %(error)s') % {'name': data[0],
'error': data[3]})) 'error': data[3]}))
return return
is_form = data[2] is_form = data[2]
@ -1195,7 +1197,9 @@ class Connection(CommonConnection, ConnectionHandlers):
key = common.xmpp.NS_XMPP_STREAMS + ' ' + self.streamError key = common.xmpp.NS_XMPP_STREAMS + ' ' + self.streamError
if key in common.xmpp.ERRORS: if key in common.xmpp.ERRORS:
sectxt2 = _('Server replied: %s') % common.xmpp.ERRORS[key][2] sectxt2 = _('Server replied: %s') % common.xmpp.ERRORS[key][2]
self.dispatch('ERROR', (pritxt, '%s\n%s' % (sectxt2, sectxt))) gajim.nec.push_incoming_event(InformationEvent(None,
conn=self, level='error', pri_txt=pritxt,
sec_txt='%s\n%s' % (sectxt2, sectxt)))
return return
# show popup # show popup
gajim.nec.push_incoming_event(ConnectionLostEvent(None, gajim.nec.push_incoming_event(ConnectionLostEvent(None,
@ -1363,9 +1367,10 @@ class Connection(CommonConnection, ConnectionHandlers):
self.disconnect(on_purpose = True) self.disconnect(on_purpose = True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self, gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline')) show='offline'))
self.dispatch('ERROR', (_('Authentication failed with "%s"') % \ gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
self._hostname, level='error', pri_txt=_('Authentication failed with "%s"') % \
_('Please check your login and password for correctness.'))) self._hostname, sec_txt=_('Please check your login and password'
'for correctness.')))
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
@ -1438,10 +1443,11 @@ class Connection(CommonConnection, ConnectionHandlers):
gajim.nec.push_incoming_event(PrivacyListRemovedEvent(None, gajim.nec.push_incoming_event(PrivacyListRemovedEvent(None,
conn=self, list_name=privacy_list)) conn=self, list_name=privacy_list))
else: else:
self.dispatch('ERROR', (_('Error while removing privacy list'), gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
_('Privacy list %s has not been removed. It is maybe active in ' level='error', pri_txt=_('Error while removing privacy '
'one of your connected resources. Deactivate it and try ' 'list'), sec_txt=_('Privacy list %s has not been removed. '
'again.') % privacy_list)) 'It is maybe active in one of your connected resources. '
'Deactivate it and tryagain.') % privacy_list))
common.xmpp.features_nb.delPrivacyList(self.connection, privacy_list, common.xmpp.features_nb.delPrivacyList(self.connection, privacy_list,
_on_del_privacy_list_result) _on_del_privacy_list_result)
@ -1516,8 +1522,10 @@ class Connection(CommonConnection, ConnectionHandlers):
if not self.privacy_rules_supported: if not self.privacy_rules_supported:
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self, gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
show=gajim.SHOW_LIST[self.connected])) show=gajim.SHOW_LIST[self.connected]))
self.dispatch('ERROR', (_('Invisibility not supported'), gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
_('Account %s doesn\'t support invisibility.') % self.name)) level='error', pri_txt=_('Invisibility not supported',
sec_txt=_('Account %s doesn\'t support invisibility.') % \
self.name)))
return return
# If we are already connected, and privacy rules are supported, send # If we are already connected, and privacy rules are supported, send
# offline presence first as it's required by XEP-0126 # offline presence first as it's required by XEP-0126
@ -2522,9 +2530,11 @@ class Connection(CommonConnection, ConnectionHandlers):
if result.getID() == id_: if result.getID() == id_:
on_remove_success(True) on_remove_success(True)
return return
self.dispatch('ERROR', (_('Unregister failed'), gajim.nec.push_incoming_event(InformationEvent(None,
_('Unregistration with server %(server)s failed: ' conn=self, level='error',
'%(error)s') % {'server': hostname, pri_txt=_('Unregister failed'),
sec_txt=_('Unregistration with server %(server)s '
'failed: %(error)s') % {'server': hostname,
'error': result.getErrorMsg()})) 'error': result.getErrorMsg()}))
on_remove_success(False) on_remove_success(False)
con.RegisterHandler('iq', _on_answer, 'result', system=True) con.RegisterHandler('iq', _on_answer, 'result', system=True)

View File

@ -125,8 +125,9 @@ class ConnectionDisco:
def _agent_registered_cb(self, con, resp, agent): def _agent_registered_cb(self, con, resp, agent):
if resp.getType() == 'result': if resp.getType() == 'result':
self.dispatch('INFORMATION', (_('Registration succeeded'), gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
_('Registration with agent %s succeeded') % agent)) level='info', pri_txt=_('Registration succeeded'), sec_txt=_(
'Registration with agent %s succeeded') % agent))
self.request_subscription(agent, auto_auth=True) self.request_subscription(agent, auto_auth=True)
self.agent_registrations[agent]['roster_push'] = True self.agent_registrations[agent]['roster_push'] = True
if self.agent_registrations[agent]['sub_received']: if self.agent_registrations[agent]['sub_received']:
@ -134,8 +135,9 @@ class ConnectionDisco:
p = self.add_sha(p) p = self.add_sha(p)
self.connection.send(p) self.connection.send(p)
if resp.getType() == 'error': if resp.getType() == 'error':
self.dispatch('ERROR', (_('Registration failed'), _('Registration ' gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
'with agent %(agent)s failed with error %(error)s: ' level='error', pri_txt=_('Registration failed'), sec_txt=_(
'Registration with agent %(agent)s failed with error %(error)s:'
' %(error_msg)s') % {'agent': agent, 'error': resp.getError(), ' %(error_msg)s') % {'agent': agent, 'error': resp.getError(),
'error_msg': resp.getErrorMsg()})) 'error_msg': resp.getErrorMsg()}))
@ -328,7 +330,8 @@ class ConnectionVcard:
fil.write(str(card)) fil.write(str(card))
fil.close() fil.close()
except IOError, e: except IOError, e:
self.dispatch('ERROR', (_('Disk Write Error'), str(e))) gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
level='error', pri_txt=_('Disk Write Error'), sec_txt=str(e)))
def get_cached_vcard(self, fjid, is_fake_jid=False): def get_cached_vcard(self, fjid, is_fake_jid=False):
""" """
@ -564,9 +567,10 @@ class ConnectionVcard:
self.disconnect(on_purpose=True) self.disconnect(on_purpose=True)
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self, gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline')) show='offline'))
self.dispatch('ERROR', (_('Invisibility not supported'), gajim.nec.push_incoming_event(InformationEvent(None,
_('Account %s doesn\'t support invisibility.') % \ conn=self, level='error', pri_txt=_('Invisibility not '
self.name)) 'supported'), sec_txt=_('Account %s doesn\'t support '
'invisibility.') % self.name))
return return
# Ask metacontacts before roster # Ask metacontacts before roster
self.get_metacontacts() self.get_metacontacts()

View File

@ -997,8 +997,9 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
try: try:
self.get_jid_resource() self.get_jid_resource()
except helpers.InvalidFormat: except helpers.InvalidFormat:
self.conn.dispatch('ERROR', (_('Invalid Jabber ID'), gajim.nec.push_incoming_event(InformationEvent(None, conn=self.conn,
_('A message from a non-valid JID arrived, it has been ' level='error', pri_txt=_('Invalid Jabber ID'),
sec_txt=_('A message from a non-valid JID arrived, it has been '
'ignored.'))) 'ignored.')))
return return
@ -1027,9 +1028,11 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
try: try:
self.get_jid_resource() self.get_jid_resource()
except helpers.InvalidFormat: except helpers.InvalidFormat:
self.conn.dispatch('ERROR', (_('Invalid Jabber ID'), gajim.nec.push_incoming_event(InformationEvent(None,
_('A message from a non-valid JID arrived, it has been ' conn=self.conn, level='error',
'ignored.'))) pri_txt=_('Invalid Jabber ID'),
sec_txt=_('A message from a non-valid JID arrived, it '
'has been ignored.')))
return return
self.forwarded = True self.forwarded = True
elif sent_tag: elif sent_tag:
@ -1041,9 +1044,11 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
try: try:
self.get_jid_resource() self.get_jid_resource()
except helpers.InvalidFormat: except helpers.InvalidFormat:
self.conn.dispatch('ERROR', (_('Invalid Jabber ID'), gajim.nec.push_incoming_event(InformationEvent(None,
_('A message from a non-valid JID arrived, it has been ' conn=self.conn, level='error',
'ignored.'))) pri_txt=_('Invalid Jabber ID'),
sec_txt=_('A message from a non-valid JID arrived, it '
'has been ignored.')))
return return
self.forwarded = True self.forwarded = True
self.sent = True self.sent = True
@ -2268,3 +2273,10 @@ class MessageOutgoingEvent(nec.NetworkOutgoingEvent):
class ClientCertPassphraseEvent(nec.NetworkIncomingEvent): class ClientCertPassphraseEvent(nec.NetworkIncomingEvent):
name = 'client-cert-passphrase' name = 'client-cert-passphrase'
base_network_events = [] base_network_events = []
class InformationEvent(nec.NetworkIncomingEvent):
name = 'information'
base_network_events = []
def init(self):
self.popup = True

View File

@ -103,11 +103,12 @@ class JingleRTPContent(JingleContent):
bin = gst.parse_bin_from_description(pipeline, True) bin = gst.parse_bin_from_description(pipeline, True)
return bin return bin
except GError, error_str: except GError, error_str:
self.session.connection.dispatch('ERROR', gajim.nec.push_incoming_event(InformationEvent(None,
(_("%s configuration error") % text.capitalize(), conn=self.session.connection, level='error',
_("Couldn't setup %s. Check your configuration.\n\n" pri_txt=_('%s configuration error') % text.capitalize(),
"Pipeline was:\n%s\n\n" sec_txt=_("Couldn't setup %s. Check your configuration.\n\n"
"Error was:\n%s") % (text, pipeline, error_str))) "Pipeline was:\n%s\n\nError was:\n%s") % (text, pipeline,
error_str)))
raise JingleContentSetupException raise JingleContentSetupException
def add_remote_candidates(self, candidates): def add_remote_candidates(self, candidates):
@ -201,9 +202,10 @@ class JingleRTPContent(JingleContent):
# or raise an error, Jingle way # or raise an error, Jingle way
# or maybe one-sided stream? # or maybe one-sided stream?
if not self.stream_failed_once: if not self.stream_failed_once:
self.session.connection.dispatch('ERROR', gajim.nec.push_incoming_event(InformationEvent(None,
(_("GStreamer error"), conn=self.session.connection, level='error',
_("Error: %s\nDebug: %s" % (message.structure['gerror'], pri_txt=_('GStreamer error'), sec_txt=_('Error: %s\nDebug: '
'%s' % (message.structure['gerror'],
message.structure['debug'])))) message.structure['debug']))))
sink_pad = self.p2psession.get_property('sink-pad') sink_pad = self.p2psession.get_property('sink-pad')

View File

@ -374,8 +374,9 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
port = gajim.config.get('file_transfers_port') port = gajim.config.get('file_transfers_port')
self._add_streamhosts_to_query(query, sender, port, my_ips) self._add_streamhosts_to_query(query, sender, port, my_ips)
except socket.gaierror: except socket.gaierror:
self.dispatch('ERROR', (_('Wrong host'), gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
_('Invalid local address? :-O'))) level='error', pri_txt=_('Wrong host'),
sec_txt=_('Invalid local address? :-O')))
def _add_addiditional_streamhosts_to_query(self, query, file_props): def _add_addiditional_streamhosts_to_query(self, query, file_props):
sender = file_props['sender'] sender = file_props['sender']

View File

@ -189,8 +189,9 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
alt_name=alt_name)) alt_name=alt_name))
def _on_error(self, message): def _on_error(self, message):
self.dispatch('ERROR', (_('Avahi error'), gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
_('%s\nLink-local messaging might not work properly.') % message)) level='error', pri_txt=_('Avahi error'), sec_txt=_('%s\nLink-local '
'messaging might not work properly.') % message))
def connect(self, show='online', msg=''): def connect(self, show='online', msg=''):
self.get_config_values_or_default() self.get_config_values_or_default()

View File

@ -2575,10 +2575,11 @@ class AccountsWindow:
return return
if gajim.ZEROCONF_ACC_NAME in gajim.connections and not \ if gajim.ZEROCONF_ACC_NAME in gajim.connections and not \
gajim.connections[gajim.ZEROCONF_ACC_NAME].is_zeroconf: gajim.connections[gajim.ZEROCONF_ACC_NAME].is_zeroconf:
gajim.connections[gajim.ZEROCONF_ACC_NAME].dispatch('ERROR', gajim.nec.push_incoming_event(InformationEvent(None,
(_('Account Local already exists.'), conn=gajim.connections[gajim.ZEROCONF_ACC_NAME],
_('Please rename or remove it before enabling link-local messaging' level='error', pri_txt=_('Account Local already exists.'),
'.'))) sec_txt=_('Please rename or remove it before enabling '
'link-local messaging.')))
return return
if gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'active') \ if gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'active') \

View File

@ -105,10 +105,6 @@ class Interface:
### Methods handling events from connection ### Methods handling events from connection
################################################################################ ################################################################################
def handle_event_error(self, unused, data):
#('ERROR', account, (title_text, section_text))
dialogs.ErrorDialog(data[0], data[1])
def handle_event_db_error(self, unused, data): def handle_event_db_error(self, unused, data):
#('DB_ERROR', account, (title_text, section_text)) #('DB_ERROR', account, (title_text, section_text))
if self.db_error_dialog: if self.db_error_dialog:
@ -118,9 +114,18 @@ class Interface:
self.db_error_dialog = None self.db_error_dialog = None
self.db_error_dialog.connect('destroy', destroyed) self.db_error_dialog.connect('destroy', destroyed)
def handle_event_information(self, unused, data): def handle_event_information(self, obj):
#('INFORMATION', account, (title_text, section_text)) if obj.popup:
dialogs.InformationDialog(data[0], data[1]) if obj.level == 'error':
cls = dialogs.ErrorDialog
elif obj.level == 'warn':
cls = dialogs.WarningDialog
elif obj.level == 'info':
cls = dialogs.InformationDialog
else:
return
cls(obj.pri_txt, obj.sec_txt)
def handle_ask_new_nick(self, account, room_jid): def handle_ask_new_nick(self, account, room_jid):
title = _('Unable to join group chat') title = _('Unable to join group chat')
@ -1372,9 +1377,7 @@ class Interface:
def create_core_handlers_list(self): def create_core_handlers_list(self):
self.handlers = { self.handlers = {
'ERROR': [self.handle_event_error],
'DB_ERROR': [self.handle_event_db_error], 'DB_ERROR': [self.handle_event_db_error],
'INFORMATION': [self.handle_event_information],
'FILE_SEND_ERROR': [self.handle_event_file_send_error], 'FILE_SEND_ERROR': [self.handle_event_file_send_error],
'atom-entry-received': [self.handle_atom_entry], 'atom-entry-received': [self.handle_atom_entry],
'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase], 'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase],
@ -1392,6 +1395,7 @@ class Interface:
'gpg-password-required': [self.handle_event_gpg_password_required], 'gpg-password-required': [self.handle_event_gpg_password_required],
'gpg-trust-key': [self.handle_event_gpg_trust_key], 'gpg-trust-key': [self.handle_event_gpg_trust_key],
'http-auth-received': [self.handle_event_http_auth], 'http-auth-received': [self.handle_event_http_auth],
'information': [self.handle_event_information],
'insecure-password': [self.handle_event_insecure_password], 'insecure-password': [self.handle_event_insecure_password],
'insecure-ssl-connection': \ 'insecure-ssl-connection': \
[self.handle_event_insecure_ssl_connection], [self.handle_event_insecure_ssl_connection],

View File

@ -96,14 +96,18 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
obj.msg_id = gajim.logger.write(log_type, obj.fjid, obj.msg_id = gajim.logger.write(log_type, obj.fjid,
msg_to_log, tim=obj.timestamp, subject=obj.subject) msg_to_log, tim=obj.timestamp, subject=obj.subject)
except exceptions.PysqliteOperationalError, e: except exceptions.PysqliteOperationalError, e:
self.conn.dispatch('ERROR', (_('Disk WriteError'), str(e))) gajim.nec.push_incoming_event(InformationEvent(None,
conn=self.conn, level='error', pri_txt=_('Disk WriteError'),
sec_txt=str(e)))
except exceptions.DatabaseMalformed: except exceptions.DatabaseMalformed:
pritext = _('Database Error') pritext = _('Database Error')
sectext = _('The database file (%s) cannot be read. Try to ' sectext = _('The database file (%s) cannot be read. Try to '
'repair it (see http://trac.gajim.org/wiki/DatabaseBackup) ' 'repair it (see http://trac.gajim.org/wiki/DatabaseBackup) '
'or remove it (all history will be lost).') % \ 'or remove it (all history will be lost).') % \
common.logger.LOG_DB_PATH common.logger.LOG_DB_PATH
self.conn.dispatch('ERROR', (pritext, sectext)) gajim.nec.push_incoming_event(InformationEvent(None,
conn=self.conn, level='error', pri_txt=pritxt,
sec_txt=sectxt))
treat_as = gajim.config.get('treat_incoming_messages') treat_as = gajim.config.get('treat_incoming_messages')
if treat_as: if treat_as: