summaryrefslogtreecommitdiff
path: root/caribou/common
diff options
context:
space:
mode:
Diffstat (limited to 'caribou/common')
-rw-r--r--caribou/common/setting_types.py38
-rw-r--r--caribou/common/settings.py2
-rw-r--r--caribou/common/settings_manager.py25
3 files changed, 47 insertions, 18 deletions
diff --git a/caribou/common/setting_types.py b/caribou/common/setting_types.py
index 17faa61..5b8aa95 100644
--- a/caribou/common/setting_types.py
+++ b/caribou/common/setting_types.py
@@ -1,4 +1,5 @@
import gobject
+from gi.repository import GConf
GCONF_DIR="/apps/caribou/osk/"
@@ -36,7 +37,6 @@ class Setting(gobject.GObject):
self._sensitive = sensitive
self.emit('sensitivity-changed', sensitive)
-
def __len__(self):
return len(self.children)
@@ -56,7 +56,7 @@ class SettingsGroup(Setting):
pass
class ValueSetting(Setting):
- gconf_type = ''
+ gconf_type = GConf.ValueType.INVALID
entry_type=ENTRY_DEFAULT
def __init__(self, name, label, default, short_desc="", long_desc="",
allowed=[], entry_type=ENTRY_DEFAULT, sensitive=None,
@@ -80,7 +80,7 @@ class ValueSetting(Setting):
@value.setter
def value(self, val):
- _val = self.convert_value(val)
+ _val = self.convert_value(self._from_gconf_value(val))
if self.allowed and _val not in [a for a, b in self.allowed]:
raise ValueError, "'%s' not a valid value" % _val
self._value = _val
@@ -98,8 +98,32 @@ class ValueSetting(Setting):
def gconf_default(self):
return self.default
+ def set_gconf_value(self, val):
+ if val.type == GConf.ValueType.BOOL:
+ return val.set_bool(self.value)
+ if val.type == GConf.ValueType.FLOAT:
+ return val.set_float(self.value)
+ if val.type == GConf.ValueType.INT:
+ return val.set_int(self.value)
+ if val.type == GConf.ValueType.STRING:
+ return val.set_string(self.value)
+
+ def _from_gconf_value(self, val):
+ if not isinstance(val, GConf.Value):
+ return val
+ if val.type == GConf.ValueType.BOOL:
+ return val.get_bool()
+ if val.type == GConf.ValueType.FLOAT:
+ return val.get_float()
+ if val.type == GConf.ValueType.INT:
+ return val.get_int()
+ if val.type == GConf.ValueType.STRING:
+ return val.get_string()
+
+ return val.to_string()
+
class BooleanSetting(ValueSetting):
- gconf_type = 'boolean'
+ gconf_type = GConf.ValueType.BOOL
entry_type = ENTRY_CHECKBOX
def convert_value(self, val):
# Almost anything could be a boolean.
@@ -110,7 +134,7 @@ class BooleanSetting(ValueSetting):
str(self.default).lower()
class IntegerSetting(ValueSetting):
- gconf_type = 'int'
+ gconf_type = GConf.ValueType.INT
entry_type = ENTRY_SPIN
def __init__(self, *args, **kwargs):
self.min = kwargs.pop('min', gobject.G_MININT)
@@ -121,7 +145,7 @@ class IntegerSetting(ValueSetting):
return int(val)
class FloatSetting(ValueSetting):
- gconf_type = 'float'
+ gconf_type = GConf.ValueType.FLOAT
entry_type = ENTRY_SPIN
def __init__(self, *args, **kwargs):
self.min = kwargs.pop('min', gobject.G_MINFLOAT)
@@ -132,7 +156,7 @@ class FloatSetting(ValueSetting):
return float(val)
class StringSetting(ValueSetting):
- gconf_type = 'string'
+ gconf_type = GConf.ValueType.STRING
def convert_value(self, val):
return str(val)
diff --git a/caribou/common/settings.py b/caribou/common/settings.py
index 179974a..09a23a9 100644
--- a/caribou/common/settings.py
+++ b/caribou/common/settings.py
@@ -166,7 +166,7 @@ if __name__ == "__main__":
doc, schema, [('key', '/schemas' + setting.gconf_key),
('applyto', setting.gconf_key),
('owner', 'caribou'),
- ('type', setting.gconf_type),
+ ('type', setting.gconf_type.value_nick),
('default', setting.gconf_default)])
locale = doc.createElement('locale')
locale.setAttribute('name', 'C')
diff --git a/caribou/common/settings_manager.py b/caribou/common/settings_manager.py
index 256ef76..92b5137 100644
--- a/caribou/common/settings_manager.py
+++ b/caribou/common/settings_manager.py
@@ -1,5 +1,5 @@
import os
-import gconf
+from gi.repository import GConf
from setting_types import *
from settings import settings
import const
@@ -7,9 +7,9 @@ import const
class _SettingsManager(object):
def __init__(self, settings):
self.groups = settings
- self.gconf_client = gconf.client_get_default()
+ self.gconf_client = GConf.Client.get_default()
self.gconf_client.add_dir(const.CARIBOU_GCONF,
- gconf.CLIENT_PRELOAD_NONE)
+ GConf.ClientPreloadType.PRELOAD_NONE)
self._settings_map = {}
self._map_settings(self.groups)
@@ -35,18 +35,20 @@ class _SettingsManager(object):
if isinstance(setting, SettingsGroup):
continue
try:
- setting.value = self.gconf_client.get_value(setting.gconf_key)
+ setting.value = self.gconf_client.get(setting.gconf_key)
except ValueError:
- self.gconf_client.set_value(setting.gconf_key, setting.value)
+ val = GConf.Value.new(setting.gconf_type)
+ setting.set_gconf_value(val)
+ self.gconf_client.set(setting.gconf_key, val)
self._change_dependant_sensitivity(setting)
handler_id = setting.connect('value-changed',
self._on_value_changed)
- self.gconf_client.notify_add(setting.gconf_key,
- self._gconf_setting_changed_cb,
- (setting, handler_id))
+ #self.gconf_client.notify_add(setting.gconf_key,
+ # self._gconf_setting_changed_cb,
+ # (setting, handler_id))
def _change_dependant_sensitivity(self, setting):
for name in setting.insensitive_when_false:
@@ -59,8 +61,11 @@ class _SettingsManager(object):
child.sensitive = i == index
def _on_value_changed(self, setting, value):
- if value != self.gconf_client.get_value(setting.gconf_key):
- self.gconf_client.set_value(setting.gconf_key, value)
+ if value != self.gconf_client.get(setting.gconf_key):
+ print setting.gconf_type
+ val = GConf.Value.new(setting.gconf_type)
+ setting.set_gconf_value(val)
+ self.gconf_client.set(setting.gconf_key, val)
self._change_dependant_sensitivity(setting)
def _gconf_setting_changed_cb(self, client, connection_id, entry, data):