Port InformationEvent handling to new interface

This commit is contained in:
Philipp Hörist 2017-12-09 00:15:26 +01:00
parent 6926bdaee0
commit 786ef96400
8 changed files with 127 additions and 70 deletions

View File

@ -275,19 +275,15 @@ class CommonConnection:
try: try:
self.check_jid(jid) self.check_jid(jid)
except helpers.InvalidFormat: except helpers.InvalidFormat:
app.nec.push_incoming_event(InformationEvent(None, app.nec.push_incoming_event(InformationEvent(
conn=self, level='error', pri_txt=_('Invalid JID'), None, dialog_name='invalid-jid', args=jid))
sec_txt=_('It is not possible to send a message '
'to %s, this JID is not valid.') % jid))
return return
else: else:
try: try:
self.check_jid(obj.jid) self.check_jid(obj.jid)
except helpers.InvalidFormat: except helpers.InvalidFormat:
app.nec.push_incoming_event(InformationEvent(None, conn=self, app.nec.push_incoming_event(InformationEvent(
level='error', pri_txt=_('Invalid JID'), sec_txt=_( None, dialog_name='invalid-jid', args=jid))
'It is not possible to send a message to %s, this JID is not '
'valid.') % obj.jid))
return return
if obj.message and not obj.xhtml and app.config.get( if obj.message and not obj.xhtml and app.config.get(
@ -937,11 +933,9 @@ 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
app.nec.push_incoming_event(InformationEvent(None, app.nec.push_incoming_event(InformationEvent(
conn=self, level='error', pri_txt=_('Invalid answer'), None, dialog_name='invalid-answer',
sec_txt=_('Transport %(name)s answered wrongly to ' kwargs={'name': data[0], 'error': data[3]}))
'register 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]
@ -1063,11 +1057,9 @@ class Connection(CommonConnection, ConnectionHandlers):
try: try:
helpers.idn_to_ascii(custom_h) helpers.idn_to_ascii(custom_h)
except Exception: except Exception:
app.nec.push_incoming_event(InformationEvent(None, app.nec.push_incoming_event(InformationEvent(
conn=self, level='error', None, dialog_name='invalid-custom-hostname',
pri_txt=_('Wrong Custom Hostname'), args=custom_h))
sec_txt='Wrong custom hostname "%s". Ignoring it.' \
% custom_h))
use_custom = False use_custom = False
# create connection if it doesn't already exist # create connection if it doesn't already exist
@ -1584,11 +1576,8 @@ class Connection(CommonConnection, ConnectionHandlers):
app.nec.push_incoming_event(PrivacyListRemovedEvent(None, app.nec.push_incoming_event(PrivacyListRemovedEvent(None,
conn=self, list_name=privacy_list)) conn=self, list_name=privacy_list))
else: else:
app.nec.push_incoming_event(InformationEvent(None, conn=self, app.nec.push_incoming_event(InformationEvent(
level='error', pri_txt=_('Error while removing privacy ' None, dialog_name='privacy-list-error', args=privacy_list))
'list'), sec_txt=_('Privacy list %s has not been removed. '
'It is maybe active in one of your connected resources. '
'Deactivate it and try again.') % privacy_list))
nbxmpp.features_nb.delPrivacyList(self.connection, privacy_list, nbxmpp.features_nb.delPrivacyList(self.connection, privacy_list,
_on_del_privacy_list_result) _on_del_privacy_list_result)
@ -1771,10 +1760,8 @@ class Connection(CommonConnection, ConnectionHandlers):
if not self.privacy_rules_supported: if not self.privacy_rules_supported:
app.nec.push_incoming_event(OurShowEvent(None, conn=self, app.nec.push_incoming_event(OurShowEvent(None, conn=self,
show=app.SHOW_LIST[self.connected])) show=app.SHOW_LIST[self.connected]))
app.nec.push_incoming_event(InformationEvent(None, conn=self, app.nec.push_incoming_event(InformationEvent(
level='error', pri_txt=_('Invisibility not supported'), None, dialog_name='invisibility-not-supported', args=self.name))
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
@ -1896,10 +1883,8 @@ class Connection(CommonConnection, ConnectionHandlers):
self.disconnect(on_purpose=True) self.disconnect(on_purpose=True)
app.nec.push_incoming_event(OurShowEvent(None, conn=self, app.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline')) show='offline'))
app.nec.push_incoming_event(InformationEvent(None, app.nec.push_incoming_event(InformationEvent(
conn=self, level='error', pri_txt=_('Invisibility not ' None, dialog_name='invisibility-not-supported', args=self.name))
'supported'), sec_txt=_('Account %s doesn\'t support '
'invisibility.') % self.name))
return return
if self.blocking_supported: if self.blocking_supported:
self._request_blocking() self._request_blocking()
@ -2917,12 +2902,9 @@ class Connection(CommonConnection, ConnectionHandlers):
if result.getID() == id_: if result.getID() == id_:
on_remove_success(True) on_remove_success(True)
return return
app.nec.push_incoming_event(InformationEvent(None, app.nec.push_incoming_event(InformationEvent(
conn=self, level='error', None, dialog_name='unregister-error',
pri_txt=_('Unregister failed'), kwargs={'server': hostname, 'error': result.getErrorMsg()}))
sec_txt=_('Unregistration with server %(server)s '
'failed: %(error)s') % {'server': hostname,
'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)
con.SendAndWaitForResponse(iq) con.SendAndWaitForResponse(iq)

View File

@ -118,10 +118,8 @@ class ConnectionDisco:
callback() callback()
return return
app.nec.push_incoming_event( app.nec.push_incoming_event(
InformationEvent(None, conn=self, InformationEvent(
level='error', None, dialog_name='unable-join-groupchat', args=error))
pri_txt=_('Unable to join Groupchat'),
sec_txt=error))
def request_register_agent_info(self, agent): def request_register_agent_info(self, agent):
if not self.connection or self.connected < 2: if not self.connection or self.connected < 2:
@ -138,9 +136,8 @@ 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':
app.nec.push_incoming_event(InformationEvent(None, conn=self, app.nec.push_incoming_event(InformationEvent(
level='info', pri_txt=_('Registration succeeded'), sec_txt=_( None, dialog_name='agent-register-success', args=agent))
'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']:
@ -148,11 +145,11 @@ 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':
app.nec.push_incoming_event(InformationEvent(None, conn=self, app.nec.push_incoming_event(InformationEvent(
level='error', pri_txt=_('Registration failed'), sec_txt=_( None, dialog_name='agent-register-error',
'Registration with agent %(agent)s failed with error %(error)s:' kwargs={'agent': agent,
' %(error_msg)s') % {'agent': agent, 'error': resp.getError(), 'error': resp.getError(),
'error_msg': resp.getErrorMsg()})) 'error_msg': resp.getErrorMsg()}))
def register_agent(self, agent, info, is_form=False): def register_agent(self, agent, info, is_form=False):
if not self.connection or self.connected < 2: if not self.connection or self.connected < 2:

View File

@ -2905,8 +2905,18 @@ class InformationEvent(nec.NetworkIncomingEvent):
base_network_events = [] base_network_events = []
def init(self): def init(self):
self.args = None
self.kwargs = {}
self.dialog_name = None
self.popup = True self.popup = True
def generate(self):
if self.args is None:
self.args = ()
else:
self.args = (self.args,)
return True
class BlockingEvent(nec.NetworkIncomingEvent): class BlockingEvent(nec.NetworkIncomingEvent):
name = 'blocking' name = 'blocking'
base_network_events = [] base_network_events = []

View File

@ -228,11 +228,9 @@ class JingleRTPContent(JingleContent):
if not self.stream_failed_once: if not self.stream_failed_once:
app.nec.push_incoming_event( app.nec.push_incoming_event(
InformationEvent( InformationEvent(
None, conn=self.session.connection, level='error', None, dialog_name='gstreamer-error',
pri_txt=_('GStreamer error'), kwargs={'error': message.get_structure().get_value('gerror'),
sec_txt=_('Error: %(error)s\nDebug: %(debug)s' % { 'debug': message.get_structure().get_value('debug')}))
'error': message.get_structure().get_value('gerror'),
'debug': message.get_structure().get_value('debug')})))
sink_pad = self.p2psession.get_property('sink-pad') sink_pad = self.p2psession.get_property('sink-pad')

View File

@ -401,9 +401,8 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
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:
from gajim.common.connection_handlers_events import InformationEvent from gajim.common.connection_handlers_events import InformationEvent
app.nec.push_incoming_event(InformationEvent(None, conn=self, app.nec.push_incoming_event(
level='error', pri_txt=_('Wrong host'), InformationEvent(None, dialog_name='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,9 +189,8 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
alt_name=alt_name)) alt_name=alt_name))
def _on_error(self, message): def _on_error(self, message):
app.nec.push_incoming_event(InformationEvent(None, conn=self, app.nec.push_incoming_event(InformationEvent(
level='error', pri_txt=_('Avahi error'), sec_txt=_('%s\nLink-local ' None, dialog_name='avahi-error', args=message))
'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

@ -23,6 +23,7 @@ from gi.repository import GLib
from gajim.common.app import app from gajim.common.app import app
from gajim.dialogs import ErrorDialog from gajim.dialogs import ErrorDialog
from gajim.dialogs import InformationDialog
Message = namedtuple('Message', ['title', 'text', 'dialog']) Message = namedtuple('Message', ['title', 'text', 'dialog'])
@ -37,6 +38,12 @@ messages = {
'%s', '%s',
ErrorDialog), ErrorDialog),
'invalid-jid': Message(
_('Invalid JID'),
_('It is not possible to send a message '
'to %s, this JID is not valid.'),
ErrorDialog),
'unread-events-on-remove-account': Message( 'unread-events-on-remove-account': Message(
_('Unread events'), _('Unread events'),
_('Read all pending events before removing this account.'), _('Read all pending events before removing this account.'),
@ -67,6 +74,65 @@ messages = {
_('The JID you entered is already in the list. Choose another one.'), _('The JID you entered is already in the list. Choose another one.'),
ErrorDialog), ErrorDialog),
'invalid-answer': Message(
_('Invalid answer'),
_('Transport %(name)s answered wrongly to '
'register request: %(error)s'),
ErrorDialog),
'invalid-custom-hostname': Message(
_('Wrong Custom Hostname'),
_('Wrong custom hostname "%s". Ignoring it.'),
ErrorDialog),
'privacy-list-error': Message(
_('Error while removing privacy list'),
_('Privacy list %s has not been removed. '
'It is maybe active in one of your connected resources. '
'Deactivate it and try again.'),
ErrorDialog),
'invisibility-not-supported': Message(
_('Invisibility not supported'),
_('Account %s doesn\'t support invisibility.'),
ErrorDialog),
'unregister-error': Message(
_('Unregister failed'),
_('Unregistration with server %(server)s failed: %(error)s'),
ErrorDialog),
'agent-register-success': Message(
_('Registration succeeded'),
_('Registration with agent %s succeeded'),
InformationDialog),
'agent-register-error': Message(
_('Registration failed'),
_('Registration with agent %(agent)s failed with error %(error)s: '
'%(error_msg)s'),
ErrorDialog),
'unable-join-groupchat': Message(
_('Unable to join Groupchat'),
'%s',
ErrorDialog),
'gstreamer-error': Message(
_('GStreamer error'),
_('Error: %(error)s\nDebug: %(debug)s'),
ErrorDialog),
'wrong-host': Message(
_('Wrong host'),
_('Invalid local address? :-O'),
ErrorDialog),
'avahi-error': Message(
_('Avahi error'),
_('%s\nLink-local messaging might not work properly.'),
ErrorDialog),
} }

View File

@ -132,17 +132,23 @@ class Interface:
@staticmethod @staticmethod
def handle_event_information(obj): def handle_event_information(obj):
if obj.popup: if not obj.popup:
if obj.level == 'error': return
cls = dialogs.ErrorDialog
elif obj.level == 'warn':
cls = dialogs.WarningDialog
elif obj.level == 'info':
cls = dialogs.InformationDialog
else:
return
cls(obj.pri_txt, GLib.markup_escape_text(obj.sec_txt)) if obj.dialog_name is not None:
get_dialog(obj.dialog_name, *obj.args, **obj.kwargs)
return
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, GLib.markup_escape_text(obj.sec_txt))
@staticmethod @staticmethod
def raise_dialog(name, *args, **kwargs): def raise_dialog(name, *args, **kwargs):