From bbb75bcdf15ecb42bca1da8450d6381e03a9e8ed Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Fri, 4 Sep 2009 21:02:55 +0200
Subject: [PATCH] clean spell languages list only once. Fixes #5228

---
 src/chat_control.py | 46 +++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/src/chat_control.py b/src/chat_control.py
index 361113c635..4d2a8806ff 100644
--- a/src/chat_control.py
+++ b/src/chat_control.py
@@ -64,6 +64,17 @@ except ImportError:
 #echo "{_('en'):'en'",$LANG"}"
 langs = {_('English'): 'en', _('Belarusian'): 'be', _('Bulgarian'): 'bg', _('Breton'): 'br', _('Czech'): 'cs', _('German'): 'de', _('Greek'): 'el', _('British'): 'en_GB', _('Esperanto'): 'eo', _('Spanish'): 'es', _('Basque'): 'eu', _('French'): 'fr', _('Croatian'): 'hr', _('Italian'): 'it', _('Norwegian (b)'): 'nb', _('Dutch'): 'nl', _('Norwegian'): 'no', _('Polish'): 'pl', _('Portuguese'): 'pt', _('Brazilian Portuguese'): 'pt_BR', _('Russian'): 'ru', _('Serbian'): 'sr', _('Slovak'): 'sk', _('Swedish'): 'sv', _('Chinese (Ch)'): 'zh_CN'}
 
+if gajim.config.get('use_speller') and HAS_GTK_SPELL:
+	# loop removing non-existent dictionaries
+	# iterating on a copy
+	tv = gtk.TextView()
+	spell = gtkspell.Spell(tv)
+	for lang in dict(langs):
+		try:
+			spell.set_language(langs[lang])
+		except OSError:
+			del langs[lang]
+
 ################################################################################
 class ChatControlBase(MessageControl):
 	'''A base class containing a banner, ConversationTextview, MessageTextView
@@ -292,32 +303,23 @@ class ChatControlBase(MessageControl):
 		self.msg_textview.grab_focus()
 
 	def set_speller(self):
-		try:
+		# now set the one the user selected
+		per_type = 'contacts'
+		if self.type_id == message_control.TYPE_GC:
+			per_type = 'rooms'
+		lang = gajim.config.get_per(per_type, self.contact.jid,
+			'speller_language')
+		if not lang:
+			# use the default one
 			lang = gajim.config.get('speller_language')
 			if not lang:
 				lang = gajim.LANG
-			spell = gtkspell.Spell(self.msg_textview, lang)
-			# loop removing non-existant dictionaries
-			# iterating on a copy
-			for lang in dict(langs):
-				try:
-					spell.set_language(langs[lang])
-				except OSError:
-					del langs[lang]
-			# now set the one the user selected
-			per_type = 'contacts'
-			if self.type_id == message_control.TYPE_GC:
-				per_type = 'rooms'
-			lang = gajim.config.get_per(per_type, self.contact.jid,
-				'speller_language')
-			if not lang:
-				# use the default one
-				lang = gajim.config.get('speller_language')
-			if lang:
+		if lang:
+			try:
+				gtkspell.Spell(self.msg_textview, lang)
 				self.msg_textview.lang = lang
-				spell.set_language(lang)
-		except (gobject.GError, RuntimeError, TypeError, OSError):
-			dialogs.AspellDictError(lang)
+			except (gobject.GError, RuntimeError, TypeError, OSError):
+				dialogs.AspellDictError(lang)
 
 	def on_banner_label_populate_popup(self, label, menu):
 		'''We override the default context menu and add our own menutiems'''
-- 
GitLab