ece062c
From fdda5c156d851446497bb042e1614ef1c55d9e92 Mon Sep 17 00:00:00 2001
ece062c
From: Mike FABIAN <mfabian@redhat.com>
ece062c
Date: Thu, 10 Jan 2013 11:37:59 +0100
ece062c
Subject: [PATCH] Changes in dconf values now get applied immediately
ece062c
ece062c
Changing values of dconf keys for example with
ece062c
ece062c
   dconf write /desktop/ibus/engine/table/cangjie3/chinesemode 3
ece062c
ece062c
was not applied immediately to the ibus-table engine, only
ece062c
when changing to a different input method and back this
ece062c
change was applied.
ece062c
ece062c
This commit fixes this problem.
ece062c
---
ece062c
 engine/table.py | 72 ++++++++++++++++++++++++++++++++++++++++++---------------
ece062c
 1 file changed, 53 insertions(+), 19 deletions(-)
ece062c
ece062c
diff --git a/engine/table.py b/engine/table.py
ece062c
index e171949..24ca921 100644
ece062c
--- a/engine/table.py
ece062c
+++ b/engine/table.py
ece062c
@@ -26,6 +26,7 @@ __all__ = (
ece062c
 )
ece062c
 
ece062c
 import os
ece062c
+import string
ece062c
 from gi.repository import IBus
ece062c
 from gi.repository import GLib
ece062c
 from curses import ascii
ece062c
@@ -1894,27 +1895,60 @@ class tabengine (IBus.Engine):
ece062c
             return True
ece062c
         return False
ece062c
 
ece062c
+    def config_section_normalize(self, section):
ece062c
+        # This function replaces _: with - in the dconf
ece062c
+        # section and converts to lower case to make
ece062c
+        # the comparison of the dconf sections work correctly.
ece062c
+        # I avoid using .lower() here because it is locale dependent,
ece062c
+        # when using .lower() this would not achieve the desired
ece062c
+        # effect of comparing the dconf sections case insentively
ece062c
+        # in some locales, it would fail for example if Turkish
ece062c
+        # locale (tr_TR.UTF-8) is set.
ece062c
+        if type(section) == type(u''):
ece062c
+            # translate() does not work in Python’s internal Unicode type
ece062c
+            section = section.encode('utf-8')
ece062c
+        return re.sub(r'[_:]', r'-', section).translate(
ece062c
+            string.maketrans(string.ascii_uppercase, string.ascii_lowercase ))
ece062c
+
ece062c
     def config_value_changed_cb (self, config, section, name, value):
ece062c
+        if self.config_section_normalize(self._config_section) != self.config_section_normalize(section):
ece062c
+            return
ece062c
+        print "config value %(n)s for engine %(en)s changed" %{'n': name, 'en': self._name}
ece062c
         value = variant_to_value(value)
ece062c
-        if section == self._config_section:
ece062c
-            if name == u'AutoCommit':
ece062c
-                self._auto_commit = value
ece062c
-            elif name == u'ChineseMode':
ece062c
-                self._editor._chinese_mode = value
ece062c
-            elif name == u'EnDefFullWidthLetter':
ece062c
-                self._full_width_letter[0] = value
ece062c
-            elif name == u'EnDefFullWidthPunct':
ece062c
-                self._full_width_punct[0] = value
ece062c
-            elif name == u'LookupTableOrientation':
ece062c
-                self._editor._lookup_table.set_orientation (value)
ece062c
-            elif name == u'LookupTableSelectKeys':
ece062c
-                self._editor.set_select_keys (value)
ece062c
-            elif name == u'OneChar':
ece062c
-                self._editor._onechar = value
ece062c
-            elif name == u'TabDefFullWidthLetter':
ece062c
-                self._full_width_letter[1] = value
ece062c
-            elif name == u'TabDefFullWidthPunct':
ece062c
-                self._full_width_punct[1] = value
ece062c
+        if name == u'autocommit':
ece062c
+            self._auto_commit = value
ece062c
+            self._refresh_properties()
ece062c
+            return
ece062c
+        elif name == u'chinesemode':
ece062c
+            self._editor._chinese_mode = value
ece062c
+            self._refresh_properties()
ece062c
+            return
ece062c
+        elif name == u'endeffullwidthletter':
ece062c
+            self._full_width_letter[0] = value
ece062c
+            self._refresh_properties()
ece062c
+            return
ece062c
+        elif name == u'endeffullwidthpunct':
ece062c
+            self._full_width_punct[0] = value
ece062c
+            self._refresh_properties()
ece062c
+            return
ece062c
+        elif name == u'lookuptableorientation':
ece062c
+            self._editor._lookup_table.set_orientation (value)
ece062c
+            return
ece062c
+        elif name == u'lookuptableselectkeys':
ece062c
+            self._editor.set_select_keys (value)
ece062c
+            return
ece062c
+        elif name == u'onechar':
ece062c
+            self._editor._onechar = value
ece062c
+            self._refresh_properties()
ece062c
+            return
ece062c
+        elif name == u'tabdeffullwidthletter':
ece062c
+            self._full_width_letter[1] = value
ece062c
+            self._refresh_properties()
ece062c
+            return
ece062c
+        elif name == u'tabdeffullwidthpunct':
ece062c
+            self._full_width_punct[1] = value
ece062c
+            self._refresh_properties()
ece062c
+            return
ece062c
 
ece062c
     # for further implementation :)
ece062c
     @classmethod
ece062c
-- 
ece062c
1.7.11.7
ece062c