summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfujiwarat <takao.fujiwara1@gmail.com>2013-06-19 13:48:39 +0900
committerfujiwarat <takao.fujiwara1@gmail.com>2013-06-19 13:48:39 +0900
commitdb50a2b8939a98be15de6dad5eb4e0d1ce232da7 (patch)
tree2ba83fb0fc3b0bd681794495d159a3449cacbe4a
parent579229e2cfe9c13396abaa7adc3e5a963bfd726a (diff)
downloadibus-anthy-db50a2b8939a98be15de6dad5eb4e0d1ce232da7.tar.gz
Fixed in case IBus.Bus.get_config returns NULL.
-rw-r--r--engine/factory.py8
-rw-r--r--setup/anthyprefs.py.in3
-rw-r--r--setup/main.py12
-rw-r--r--setup/prefs.py35
4 files changed, 41 insertions, 17 deletions
diff --git a/engine/factory.py b/engine/factory.py
index fbde144..7daa4a7 100644
--- a/engine/factory.py
+++ b/engine/factory.py
@@ -47,7 +47,13 @@ class EngineFactory(IBus.Factory):
self.__id = 0
self.__config = self.__bus.get_config()
- self.__config.connect('value-changed', self.__config_value_changed_cb)
+ if self.__config != None:
+ self.__config.connect('value-changed',
+ self.__config_value_changed_cb)
+ else:
+ print >> sys.stderr, \
+ 'ibus-config is not running or bus address is not correct.'
+
bus.get_connection().signal_subscribe('org.freedesktop.DBus',
'org.freedesktop.DBus',
'NameOwnerChanged',
diff --git a/setup/anthyprefs.py.in b/setup/anthyprefs.py.in
index 65c872d..b78887f 100644
--- a/setup/anthyprefs.py.in
+++ b/setup/anthyprefs.py.in
@@ -37,7 +37,8 @@ class AnthyPrefs(Prefs):
def __init__(self, bus=None, config=None):
super(AnthyPrefs, self).__init__(bus, config)
- self.default = _config
+ if _config != None:
+ self.default = _config
self.set_no_key_warning(True)
self.fetch_all()
self.set_no_key_warning(False)
diff --git a/setup/main.py b/setup/main.py
index 7562e46..68a6114 100644
--- a/setup/main.py
+++ b/setup/main.py
@@ -686,11 +686,17 @@ class AnthySetup(object):
self.__thumb_kb_layout.set_sensitive(False)
else:
self.__thumb_kb_layout.set_sensitive(True)
+
+ use_system_keyboard = False
+
try:
- use_system_keyboard = self.__config.get_value('general',
- 'use_system_keyboard_layout').get_boolean()
+ if self.__config != None:
+ use_system_keyboard = \
+ self.__config.get_value('general',
+ 'use_system_keyboard_layout').get_boolean()
except:
- use_system_keyboard = True
+ pass
+
if layout_mode and \
not use_system_keyboard:
self.__builder.get_object('thumb:warning_hbox').show()
diff --git a/setup/prefs.py b/setup/prefs.py
index d1dd22b..dedcea9 100644
--- a/setup/prefs.py
+++ b/setup/prefs.py
@@ -35,19 +35,19 @@ class Prefs(object):
self.new = {}
self.__no_key_warning = False
+ # self._config is used by AnthyPrefs .
self._config = config if config else \
bus.get_config() if bus else \
IBus.Bus().get_config()
# ibus_config_get_values enhances the performance.
- self.__has_config_get_values = hasattr(self._config, 'get_values')
+ self.__has_config_get_values = False
- # In the latest pygobject3 3.3.4 or later, g_variant_dup_strv
- # returns the allocated strv but in the previous release,
- # it returned the tuple of (strv, length)
- self.__tuple_for_variant_strv = False
- if type(GLib.Variant.new_strv([]).dup_strv()) == tuple:
- self.__tuple_for_variant_strv = True
+ if self._config != None:
+ self.__has_config_get_values = hasattr(self._config, 'get_values')
+ else:
+ print >> sys.stderr, \
+ 'ibus-config is not running or bus address is not correct.'
def __log_handler(self, domain, level, message, data):
if not data:
@@ -65,10 +65,11 @@ class Prefs(object):
elif type_string == 'b':
return variant.get_boolean()
elif type_string == 'as':
- if self.__tuple_for_variant_strv:
- return variant.dup_strv()[0]
- else:
- return variant.dup_strv()
+ # Use unpack() instead of dup_strv() in python.
+ # In the latest pygobject3 3.3.4 or later, g_variant_dup_strv
+ # returns the allocated strv but in the previous release,
+ # it returned the tuple of (strv, length)
+ return variant.unpack()
else:
print >> sys.stderr, 'Unknown variant type:', type_string
sys.abrt()
@@ -102,6 +103,9 @@ class Prefs(object):
return self.default[section][key]
def get_value_direct(self, section, key, default=None):
+ if self._config == None:
+ return default
+
s = section
section = '/'.join(
[s for s in '/'.join([self._prefix, section]).split('/') if s])
@@ -128,6 +132,9 @@ class Prefs(object):
self.fetch_section(s)
def fetch_section(self, section):
+ if self._config == None:
+ return
+
if not self.__has_config_get_values:
for k in self.keys(section):
self.fetch_item(section, k)
@@ -149,6 +156,9 @@ class Prefs(object):
self.fetch_item(section, 'show-preferences')
def fetch_item(self, section, key, readonly=False):
+ if self._config == None:
+ return
+
s = '/'.join(
[s for s in '/'.join([self._prefix, section]).split('/') if s])
try:
@@ -199,7 +209,8 @@ class Prefs(object):
if variant == None:
print >> sys.stderr, 'Unknown value type:', type(v)
sys.abrt()
- self._config.set_value(s, key, variant)
+ if self._config != None:
+ self._config.set_value(s, key, variant)
self.modified.setdefault(section, {})[key] = v
del(self.new[section][key])