From 02a0f25781595441082514015aeb45df058018e8 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 22 May 2016 23:09:49 +0200 Subject: [PATCH] remember which speller language was use for each contact. Fixes #8326 --- src/chat_control.py | 26 ++++++++++++-------------- src/gtkspell.py | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/chat_control.py b/src/chat_control.py index 79a79759b..a9556899e 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -441,11 +441,22 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): lang = gajim.LANG if lang: try: - gtkspell.Spell(self.msg_textview, lang) + self.spell = gtkspell.Spell(self.msg_textview, lang) self.msg_textview.lang = lang + self.spell.connect('language_changed', self.on_language_changed) except (GObject.GError, RuntimeError, TypeError, OSError): dialogs.AspellDictError(lang) + def on_language_changed(self, spell, lang): + per_type = 'contacts' + if self.type_id == message_control.TYPE_GC: + per_type = 'rooms' + if not gajim.config.get_per(per_type, self.contact.jid): + gajim.config.add_per(per_type, self.contact.jid) + gajim.config.set_per(per_type, self.contact.jid, 'speller_language', + lang) + self.msg_textview.lang = lang + def on_banner_label_populate_popup(self, label, menu): """ Override the default context menu and add our own menutiems @@ -480,19 +491,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): Override the default context menu and we prepend an option to switch languages """ - def _on_select_dictionary(widget, lang): - per_type = 'contacts' - if self.type_id == message_control.TYPE_GC: - per_type = 'rooms' - if not gajim.config.get_per(per_type, self.contact.jid): - gajim.config.add_per(per_type, self.contact.jid) - gajim.config.set_per(per_type, self.contact.jid, 'speller_language', - lang) - spell = gtkspell.get_from_text_view(self.msg_textview) - self.msg_textview.lang = lang - spell.set_language(lang) - widget.set_active(True) - item = Gtk.MenuItem.new_with_mnemonic(_('_Undo')) menu.prepend(item) id_ = item.connect('activate', self.msg_textview.undo) diff --git a/src/gtkspell.py b/src/gtkspell.py index cab1791f3..bb75b8e1c 100644 --- a/src/gtkspell.py +++ b/src/gtkspell.py @@ -17,6 +17,7 @@ ## You should have received a copy of the GNU General Public License ## along with Gajim. If not, see . +from gi.repository import GObject from gi.repository import Gtk import gi gi.require_version('GtkSpell', '3.0') @@ -31,9 +32,14 @@ def ensure_attached(func): return f -class Spell(object): +class Spell(GObject.GObject): + __gsignals__ = { + 'language_changed': (GObject.SignalFlags.RUN_FIRST, None, (str,)) + } - def __init__(self, textview, language=None, create=True): + def __init__(self, textview, language=None, create=True, jid=None, + per_type=None): + GObject.GObject.__init__(self) if not isinstance(textview, Gtk.TextView): raise TypeError("Textview must be derived from Gtk.TextView") spell = GtkSpell.Checker.get_from_text_view(textview) @@ -47,6 +53,7 @@ class Spell(object): raise OSError("Unable to attach spell object.") if not self.spell.set_language(language): raise OSError("Unable to set language: '%s'" % language) + self.spell.connect('language-changed', self.on_language_changed) else: if spell: @@ -54,6 +61,9 @@ class Spell(object): else: raise RuntimeError("Textview has no Spell object attached") + def on_language_changed(self, spell, lang): + self.emit('language_changed', lang) + @ensure_attached def set_language(self, language): if not self.spell.set_language(language): @@ -68,6 +78,7 @@ class Spell(object): self.spell.detach() self.spell = None +GObject.type_register(Spell) def get_from_text_view(textview): return Spell(textview, create=False)