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

View File

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

View File

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

View File

@ -228,11 +228,9 @@ class JingleRTPContent(JingleContent):
if not self.stream_failed_once:
app.nec.push_incoming_event(
InformationEvent(
None, conn=self.session.connection, level='error',
pri_txt=_('GStreamer error'),
sec_txt=_('Error: %(error)s\nDebug: %(debug)s' % {
'error': message.get_structure().get_value('gerror'),
'debug': message.get_structure().get_value('debug')})))
None, dialog_name='gstreamer-error',
kwargs={'error': message.get_structure().get_value('gerror'),
'debug': message.get_structure().get_value('debug')}))
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)
except socket.gaierror:
from gajim.common.connection_handlers_events import InformationEvent
app.nec.push_incoming_event(InformationEvent(None, conn=self,
level='error', pri_txt=_('Wrong host'),
sec_txt=_('Invalid local address? :-O')))
app.nec.push_incoming_event(
InformationEvent(None, dialog_name='wrong-host')),
def _add_addiditional_streamhosts_to_query(self, query, file_props):
sender = file_props.sender

View File

@ -189,9 +189,8 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
alt_name=alt_name))
def _on_error(self, message):
app.nec.push_incoming_event(InformationEvent(None, conn=self,
level='error', pri_txt=_('Avahi error'), sec_txt=_('%s\nLink-local '
'messaging might not work properly.') % message))
app.nec.push_incoming_event(InformationEvent(
None, dialog_name='avahi-error', args=message))
def connect(self, show='online', msg=''):
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.dialogs import ErrorDialog
from gajim.dialogs import InformationDialog
Message = namedtuple('Message', ['title', 'text', 'dialog'])
@ -37,6 +38,12 @@ messages = {
'%s',
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'),
_('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.'),
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
def handle_event_information(obj):
if obj.popup:
if obj.level == 'error':
cls = dialogs.ErrorDialog
elif obj.level == 'warn':
cls = dialogs.WarningDialog
elif obj.level == 'info':
cls = dialogs.InformationDialog
else:
return
if not obj.popup:
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
def raise_dialog(name, *args, **kwargs):