Remove unnecessary event classes

This commit is contained in:
Philipp Hörist 2019-01-03 08:33:35 +01:00
parent fcb33a10e7
commit 371756c2a5
6 changed files with 66 additions and 129 deletions

View File

@ -58,6 +58,7 @@ from gajim.common import app
from gajim.common import gpg
from gajim.common import passwords
from gajim.common import idle
from gajim.common.nec import NetworkEvent
from gajim.common.i18n import _
from gajim.common.connection_handlers import *
from gajim.common.contacts import GC_Contact
@ -421,11 +422,15 @@ class CommonConnection:
def _event_dispatcher(self, realm, event, data):
if realm == '':
if event == 'STANZA RECEIVED':
app.nec.push_incoming_event(StanzaReceivedEvent(
None, conn=self, stanza_str=str(data)))
app.nec.push_incoming_event(
NetworkEvent('stanza-received',
conn=self,
stanza_str=str(data)))
elif event == 'DATA SENT':
app.nec.push_incoming_event(StanzaSentEvent(
None, conn=self, stanza_str=str(data)))
app.nec.push_incoming_event(
NetworkEvent('stanza-sent',
conn=self,
stanza_str=str(data)))
def change_status(self, show, msg, auto=False):
if not msg:
@ -732,8 +737,8 @@ class Connection(CommonConnection, ConnectionHandlers):
reason = _('Server %(name)s answered wrongly to '
'register request: %(error)s') % {'name': data[0],
'error': data[3]}
app.nec.push_incoming_event(AccountNotCreatedEvent(
None, conn=self, reason=reason))
app.nec.push_incoming_event(NetworkEvent(
'account-not-created', conn=self, reason=reason))
return
is_form = data[2]
conf = data[1]
@ -743,15 +748,16 @@ class Connection(CommonConnection, ConnectionHandlers):
def _on_register_result(result):
if not nbxmpp.isResultNode(result):
reason = result.getErrorMsg() or result.getError()
app.nec.push_incoming_event(AccountNotCreatedEvent(
None, conn=self, reason=reason))
app.nec.push_incoming_event(NetworkEvent(
'account-not-created', conn=self, reason=reason))
return
if app.is_installed('GPG'):
self.USE_GPG = True
self.gpg = gpg.GnuPG()
app.nec.push_incoming_event(
AccountCreatedEvent(None, conn=self,
account_info=self.new_account_info))
NetworkEvent('account-created',
conn=self,
account_info=self.new_account_info))
self.new_account_info = None
self.new_account_form = None
if self.connection:
@ -773,8 +779,8 @@ class Connection(CommonConnection, ConnectionHandlers):
# requested config has changed since first connection
reason = _('Server %s provided a different '
'registration form') % data[0]
app.nec.push_incoming_event(AccountNotCreatedEvent(
None, conn=self, reason=reason))
app.nec.push_incoming_event(NetworkEvent(
'account-not-created', conn=self, reason=reason))
return
nbxmpp.features_nb.register(self.connection,
self._hostname, self.new_account_form,
@ -1039,9 +1045,12 @@ class Connection(CommonConnection, ConnectionHandlers):
if self.client_cert and app.config.get_per('accounts', self.name,
'client_cert_encrypted'):
app.nec.push_incoming_event(ClientCertPassphraseEvent(
None, conn=self, con=con, port=port,
secure_tuple=secure_tuple))
app.nec.push_incoming_event(
NetworkEvent('client-cert-passphrase',
conn=self,
con=con,
port=port,
secure_tuple=secure_tuple))
return
self.on_client_cert_passphrase('', con, port, secure_tuple)
@ -1115,8 +1124,10 @@ class Connection(CommonConnection, ConnectionHandlers):
con.RegisterDisconnectHandler(self.disconnect)
if _con_type == 'plain' and app.config.get_per('accounts', self.name,
'action_when_plaintext_connection') == 'warn':
app.nec.push_incoming_event(PlainConnectionEvent(None, conn=self,
xmpp_client=con))
app.nec.push_incoming_event(
NetworkEvent('plain-connection',
conn=self,
xmpp_client=con))
return True
if _con_type == 'plain' and app.config.get_per('accounts', self.name,
'action_when_plaintext_connection') == 'disconnect':
@ -1129,8 +1140,11 @@ class Connection(CommonConnection, ConnectionHandlers):
'warn_when_insecure_ssl_connection') and \
not self.connection_auto_accepted:
# Pyopenssl is not used
app.nec.push_incoming_event(InsecureSSLConnectionEvent(None,
conn=self, xmpp_client=con, conn_type=_con_type))
app.nec.push_incoming_event(
NetworkEvent('insecure-ssl-connection',
conn=self,
xmpp_client=con,
conn_type=_con_type))
return True
return self.connection_accepted(con, con_type)
@ -1187,9 +1201,11 @@ class Connection(CommonConnection, ConnectionHandlers):
self.process_ssl_errors()
return
app.nec.push_incoming_event(SSLErrorEvent(None, conn=self,
error_num=errnum,
cert=cert))
app.nec.push_incoming_event(
NetworkEvent('ssl-error',
conn=self,
error_num=errnum,
cert=cert))
@staticmethod
def _calculate_cert_sha256(cert):
@ -1286,8 +1302,8 @@ class Connection(CommonConnection, ConnectionHandlers):
if self.password is not None:
on_password(self.password)
else:
app.nec.push_incoming_event(PasswordRequiredEvent(
None, conn=self, on_password=on_password))
app.nec.push_incoming_event(NetworkEvent(
'password-required', conn=self, on_password=on_password))
def _auth(self):
self._register_handlers(self.connection, self._current_type)
@ -1311,7 +1327,9 @@ class Connection(CommonConnection, ConnectionHandlers):
app.con_types[self.name] = con_type
# notify the gui about con_type
app.nec.push_incoming_event(
ConnectionTypeEvent(None, conn=self, connection_type=con_type))
NetworkEvent('connection-type',
conn=self,
connection_type=con_type))
ConnectionHandlers._register_handlers(self, con, con_type)
def _on_auth_successful(self):
@ -1365,8 +1383,11 @@ class Connection(CommonConnection, ConnectionHandlers):
app.config.set_per('accounts', self.name,
'name', self.connection.User)
new_jid = app.get_jid_from_account(self.name)
app.nec.push_incoming_event(AnonymousAuthEvent(
None, conn=self, old_jid=old_jid, new_jid=new_jid))
app.nec.push_incoming_event(
NetworkEvent('anonymous-auth',
conn=self,
old_jid=old_jid,
new_jid=new_jid))
self.connected = 2
self.retrycount = 0
@ -1447,7 +1468,7 @@ class Connection(CommonConnection, ConnectionHandlers):
self.get_module('Blocking').get_blocking_list()
# Inform GUI we just signed in
app.nec.push_incoming_event(SignedInEvent(None, conn=self))
app.nec.push_incoming_event(NetworkEvent('signed-in', conn=self))
def get_signed_presence(self, msg, callback=None):
if app.config.get_per('accounts', self.name, 'gpg_sign_presence'):

View File

@ -34,6 +34,7 @@ from gajim.common import ged
from gajim.common import helpers
from gajim.common import jingle_xtls
from gajim.common import modules
from gajim.common.nec import NetworkEvent
from gajim.common.caps_cache import muc_caps_cache
from gajim.common.connection_handlers_events import *
from gajim.common.const import KindConstant
@ -360,7 +361,7 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
self.get_module('Blocking').get_blocking_list()
# Inform GUI we just signed in
app.nec.push_incoming_event(SignedInEvent(None, conn=self))
app.nec.push_incoming_event(NetworkEvent('signed-in', conn=self))
self.get_module('PEP').send_stored_publish()
self.continue_connect_info = None

View File

@ -66,9 +66,6 @@ class MessageSentEvent(nec.NetworkIncomingEvent):
self.conn.sent_message_ids = self.conn.sent_message_ids[-20000:]
return True
class MessageNotSentEvent(nec.NetworkIncomingEvent):
name = 'message-not-sent'
class MessageErrorEvent(nec.NetworkIncomingEvent):
name = 'message-error'
@ -85,9 +82,6 @@ class MessageErrorEvent(nec.NetworkIncomingEvent):
return True
return False
class AnonymousAuthEvent(nec.NetworkIncomingEvent):
name = 'anonymous-auth'
class JingleRequestReceivedEvent(nec.NetworkIncomingEvent):
name = 'jingle-request-received'
@ -133,12 +127,6 @@ class JingleErrorReceivedEvent(nec.NetworkIncomingEvent):
self.sid = self.jingle_session.sid
return True
class AccountCreatedEvent(nec.NetworkIncomingEvent):
name = 'account-created'
class AccountNotCreatedEvent(nec.NetworkIncomingEvent):
name = 'account-not-created'
class NewAccountConnectedEvent(nec.NetworkIncomingEvent):
name = 'new-account-connected'
@ -165,15 +153,6 @@ class NewAccountConnectedEvent(nec.NetworkIncomingEvent):
class NewAccountNotConnectedEvent(nec.NetworkIncomingEvent):
name = 'new-account-not-connected'
class ConnectionTypeEvent(nec.NetworkIncomingEvent):
name = 'connection-type'
class StanzaReceivedEvent(nec.NetworkIncomingEvent):
name = 'stanza-received'
class StanzaSentEvent(nec.NetworkIncomingEvent):
name = 'stanza-sent'
class BadGPGPassphraseEvent(nec.NetworkIncomingEvent):
name = 'bad-gpg-passphrase'
@ -191,9 +170,6 @@ class ConnectionLostEvent(nec.NetworkIncomingEvent):
show='offline'))
return True
class GPGTrustKeyEvent(nec.NetworkIncomingEvent):
name = 'gpg-trust-key'
class GPGPasswordRequiredEvent(nec.NetworkIncomingEvent):
name = 'gpg-password-required'
@ -201,42 +177,6 @@ class GPGPasswordRequiredEvent(nec.NetworkIncomingEvent):
self.keyid = app.config.get_per('accounts', self.conn.name, 'keyid')
return True
class PlainConnectionEvent(nec.NetworkIncomingEvent):
name = 'plain-connection'
class InsecureSSLConnectionEvent(nec.NetworkIncomingEvent):
name = 'insecure-ssl-connection'
class SSLErrorEvent(nec.NetworkIncomingEvent):
name = 'ssl-error'
class UpdateGCAvatarEvent(nec.NetworkIncomingEvent):
name = 'update-gc-avatar'
def generate(self):
return True
class UpdateRosterAvatarEvent(nec.NetworkIncomingEvent):
name = 'update-roster-avatar'
def generate(self):
return True
class UpdateRoomAvatarEvent(nec.NetworkIncomingEvent):
name = 'update-room-avatar'
def generate(self):
return True
class ZeroconfNameConflictEvent(nec.NetworkIncomingEvent):
name = 'zeroconf-name-conflict'
class PasswordRequiredEvent(nec.NetworkIncomingEvent):
name = 'password-required'
class SignedInEvent(nec.NetworkIncomingEvent):
name = 'signed-in'
class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
name = 'file-request-received'
@ -737,10 +677,6 @@ class GcMessageOutgoingEvent(nec.NetworkOutgoingEvent):
def generate(self):
return True
class ClientCertPassphraseEvent(nec.NetworkIncomingEvent):
name = 'client-cert-passphrase'
class InformationEvent(nec.NetworkIncomingEvent):
name = 'information'
@ -756,10 +692,3 @@ class InformationEvent(nec.NetworkIncomingEvent):
else:
self.args = (self.args,)
return True
class StyleChanged(nec.NetworkIncomingEvent):
name = 'style-changed'
def generate(self):
return True

View File

@ -36,6 +36,7 @@ from gi.repository import GLib
from gajim.common import app
from gajim.common import ged
from gajim.common import modules
from gajim.common.nec import NetworkEvent
from gajim.common.i18n import _
from gajim.common.connection import CommonConnection
from gajim.common.zeroconf import client_zeroconf
@ -240,8 +241,10 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
self.disconnect()
app.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline'))
app.nec.push_incoming_event(ZeroconfNameConflictEvent(None, conn=self,
alt_name=alt_name))
app.nec.push_incoming_event(
NetworkEvent('zeroconf-name-conflict',
conn=self,
alt_name=alt_name))
def _on_error(self, message):
app.nec.push_incoming_event(InformationEvent(
@ -362,7 +365,7 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
check = self.connection.announce()
else:
self.connected = STATUS_LIST.index(show)
app.nec.push_incoming_event(SignedInEvent(None, conn=self))
app.nec.push_incoming_event(NetworkEvent('signed-in', conn=self))
# stay offline when zeroconf does something wrong
if check:

View File

@ -21,11 +21,11 @@ from gi.repository import Gtk
from gi.repository import Gdk
from gajim.common import app
from gajim.common.nec import NetworkEvent
from gajim.common.i18n import _
from gajim.common.const import StyleAttr
from gajim.common.const import DialogButton
from gajim.common.const import ButtonAction
from gajim.common.connection_handlers_events import StyleChanged
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.dialogs import NewConfirmationDialog
@ -388,18 +388,18 @@ class Option(Gtk.ListBoxRow):
color_string = color.to_string()
app.css_config.set_value(
self._option.selector, self._option.attr, color_string, pre=True)
app.nec.push_incoming_event(StyleChanged(None))
app.nec.push_incoming_event(NetworkEvent('style-changed'))
def _on_font_set(self, font_button):
desc = font_button.get_font_desc()
app.css_config.set_font(self._option.selector, desc, pre=True)
app.nec.push_incoming_event(StyleChanged(None,))
app.nec.push_incoming_event(NetworkEvent('style-changed'))
def _on_remove(self, *args):
self.get_parent().remove(self)
app.css_config.remove_value(
self._option.selector, self._option.attr, pre=True)
app.nec.push_incoming_event(StyleChanged(None))
app.nec.push_incoming_event(NetworkEvent('style-changed'))
self.destroy()
def __eq__(self, other):

View File

@ -85,10 +85,10 @@ from gajim.common import socks5
from gajim.common import helpers
from gajim.common import passwords
from gajim.common import logging_helpers
from gajim.common.nec import NetworkEvent
from gajim.common.i18n import _
from gajim.common.connection_handlers_events import (
OurShowEvent, FileTransferCompletedEvent,
UpdateRosterAvatarEvent, UpdateGCAvatarEvent, UpdateRoomAvatarEvent)
OurShowEvent, FileTransferCompletedEvent)
from gajim.common.modules.httpupload import HTTPUploadProgressEvent
from gajim.common.connection import Connection
@ -614,22 +614,6 @@ class Interface:
self.gpg_passphrase[obj.keyid] = request
request.add_callback(obj.conn.name, obj.callback)
@staticmethod
def handle_event_gpg_trust_key(obj):
#('GPG_ALWAYS_TRUST', account, callback)
def on_yes(checked):
if checked:
obj.conn.gpg.always_trust.append(obj.keyID)
obj.callback(True)
def on_no():
obj.callback(False)
YesNoDialog(_('Untrusted OpenPGP key'), _('The OpenPGP key '
'used to encrypt this chat is not trusted. Do you really want to '
'encrypt this message?'), checktext=_('_Do not ask me again'),
on_response_yes=on_yes, on_response_no=on_no)
def handle_event_password_required(self, obj):
#('PASSWORD_REQUIRED', account, None)
account = obj.conn.name
@ -1359,7 +1343,6 @@ class Interface:
'muc-invitation': [self.handle_event_gc_invitation],
'muc-decline': [self.handle_event_gc_decline],
'gpg-password-required': [self.handle_event_gpg_password_required],
'gpg-trust-key': [self.handle_event_gpg_trust_key],
'http-auth-received': [self.handle_event_http_auth],
'information': [self.handle_event_information],
'insecure-ssl-connection': \
@ -2116,13 +2099,13 @@ class Interface:
def update_avatar(account=None, jid=None, contact=None, room_avatar=False):
if room_avatar:
app.nec.push_incoming_event(
UpdateRoomAvatarEvent(None, account=account, jid=jid))
NetworkEvent('update-room-avatar', account=account, jid=jid))
elif contact is None:
app.nec.push_incoming_event(
UpdateRosterAvatarEvent(None, account=account, jid=jid))
NetworkEvent('update-roster-avatar', account=account, jid=jid))
else:
app.nec.push_incoming_event(
UpdateGCAvatarEvent(None, contact=contact))
NetworkEvent('update-gc-avatar', contact=contact))
def save_avatar(self, data, publish=False):
"""