From d6b7916f2b37ea9777701a3bc8c1a5633e030ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 26 Jan 2019 21:25:33 +0100 Subject: [PATCH] Prevent callbacks on destroyed objects Fixes #9560 --- gajim/gtk/groupchat_config.py | 13 +++++++++++++ gajim/gtk/util.py | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/gajim/gtk/groupchat_config.py b/gajim/gtk/groupchat_config.py index 91ce0fb8f..1e3869745 100644 --- a/gajim/gtk/groupchat_config.py +++ b/gajim/gtk/groupchat_config.py @@ -15,6 +15,7 @@ import logging import nbxmpp +from gi.repository import Gdk from gi.repository import Gtk from gajim.common import app @@ -25,6 +26,7 @@ from gajim.common.caps_cache import muc_caps_cache from gajim.gtk.dialogs import ErrorDialog from gajim.gtk.dataform import DataFormWidget from gajim.gtk.util import get_builder +from gajim.gtk.util import ensure_not_destroyed log = logging.getLogger('gajim.gtk.groupchat_config') @@ -36,6 +38,7 @@ class GroupchatConfig(Gtk.ApplicationWindow): self.set_position(Gtk.WindowPosition.CENTER) self.set_show_menubar(False) self.set_title(_('Group Chat Configuration')) + self._destroyed = False self.account = account self.jid = jid @@ -77,6 +80,8 @@ class GroupchatConfig(Gtk.ApplicationWindow): self._ui.connect_signals(self) self.connect('delete-event', self._cancel) + self.connect('destroy', self._on_destroy) + self.connect('key-press-event', self._on_key_press) self.show_all() self._ui.stack.notify('visible-child-name') @@ -291,6 +296,10 @@ class GroupchatConfig(Gtk.ApplicationWindow): return add, remove, modified + def _on_key_press(self, _widget, event): + if event.keyval == Gdk.KEY_Escape: + self._on_cancel() + def _on_cancel(self, *args): self._cancel() self.destroy() @@ -300,6 +309,9 @@ class GroupchatConfig(Gtk.ApplicationWindow): con = app.connections[self.account] con.get_module('MUC').cancel_config(self.jid) + def _on_destroy(self, *args): + self._destroyed = True + def _set_affiliations(self): add, remove, modified = self._get_diff() @@ -339,6 +351,7 @@ class GroupchatConfig(Gtk.ApplicationWindow): con = app.connections[self.account] con.get_module('MUC').set_affiliation(self.jid, diff_dict) + @ensure_not_destroyed def _on_affiliations_received(self, result): if result.is_error: log.info('Error while requesting %s affiliations: %s', diff --git a/gajim/gtk/util.py b/gajim/gtk/util.py index 5142b1a00..aed9e6470 100644 --- a/gajim/gtk/util.py +++ b/gajim/gtk/util.py @@ -25,6 +25,7 @@ import sys import logging import xml.etree.ElementTree as ET from pathlib import Path +from functools import wraps from gi.repository import Gdk from gi.repository import Gtk @@ -489,3 +490,12 @@ def get_hardware_key_codes(keyval): if not valid: return [] return [key.keycode for key in key_map_keys] + + +def ensure_not_destroyed(func): + @wraps(func) + def func_wrapper(self, *args, **kwargs): + if self._destroyed: + return + return func(self, *args, **kwargs) + return func_wrapper