[caribou: 3/5] Use GSettings for caribou settings.



commit 994014a918ce32a08e4912ee2ac7274839d823f0
Author: Eitan Isaacson <eitan monotonous org>
Date:   Tue Mar 8 17:38:08 2011 -0500

    Use GSettings for caribou settings.

 caribou/common/setting_types.py    |    6 +++-
 caribou/common/settings.py         |    4 ++-
 caribou/common/settings_manager.py |   41 +++++++++++++----------------------
 3 files changed, 22 insertions(+), 29 deletions(-)
---
diff --git a/caribou/common/setting_types.py b/caribou/common/setting_types.py
index 130a0b5..109bf1b 100644
--- a/caribou/common/setting_types.py
+++ b/caribou/common/setting_types.py
@@ -71,6 +71,7 @@ class ValueSetting(Setting):
         self.default = default
         self.insensitive_when_false = insensitive_when_false
         self.insensitive_when_true = insensitive_when_true
+        self.hush = False
 
     @property
     def value(self):
@@ -78,11 +79,12 @@ class ValueSetting(Setting):
 
     @value.setter
     def value(self, val):
-        _val = self.convert_value(val.unpack())
+        _val = self.convert_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
-        self.emit('value-changed', _val)
+        if not self.hush:
+            self.emit('value-changed', _val)
 
     @property
     def gsettings_key(self):
diff --git a/caribou/common/settings.py b/caribou/common/settings.py
index 0393079..86ad86f 100644
--- a/caribou/common/settings.py
+++ b/caribou/common/settings.py
@@ -5,6 +5,8 @@ import caribou.common.const as const
 import caribou.ui.i18n
 import xml.dom.minidom
 
+GSETTINGS_SCHEMA = "org.gnome.caribou"
+
 try:
     import json
 except ImportError:
@@ -127,7 +129,7 @@ if __name__ == "__main__":
             doc = xml.dom.minidom.Document()
             schemafile =  doc.createElement('schemalist')
             schema = doc.createElement('schema')
-            schema.setAttribute("id", "org.gnome.caribou")
+            schema.setAttribute("id", GSETTINGS_SCHEMA)
             schema.setAttribute("path", "/apps/caribou/osk/")
             schemafile.appendChild(schema)
             self._create_schema(settings, doc, schema)
diff --git a/caribou/common/settings_manager.py b/caribou/common/settings_manager.py
index c073fef..66119f8 100644
--- a/caribou/common/settings_manager.py
+++ b/caribou/common/settings_manager.py
@@ -1,15 +1,14 @@
 import os
-from gi.repository import GConf
+from gi.repository import Gio
 from setting_types import *
-from settings import settings
+from settings import settings, GSETTINGS_SCHEMA
 import const
 
 class _SettingsManager(object):
     def __init__(self, settings):
         self.groups = settings
-        self.gconf_client = GConf.Client.get_default()
-        self.gconf_client.add_dir(const.CARIBOU_GCONF,
-                                  GConf.ClientPreloadType.PRELOAD_NONE)
+        self._gsettings = Gio.Settings(GSETTINGS_SCHEMA)
+        self._gsettings.connect("changed", self._gsettings_changed_cb)
         self._settings_map = {}
         self._map_settings(self.groups)
 
@@ -34,21 +33,12 @@ class _SettingsManager(object):
         for setting in self._settings_map.values():
             if isinstance(setting, SettingsGroup):
                 continue
-            try:
-                setting.value = self.gconf_client.get(setting.gconf_key)
-            except ValueError:
-                val = GConf.Value.new(setting.gconf_type)
-                setting.set_gconf_value(val)
-                self.gconf_client.set(setting.gconf_key, val)
+            setting.value = \
+                self._gsettings.get_value(setting.gsettings_key).unpack()
 
             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))
+            setting.connect('value-changed', self._on_value_changed)
 
     def _change_dependant_sensitivity(self, setting):
         for name in setting.insensitive_when_false:
@@ -61,19 +51,18 @@ class _SettingsManager(object):
                 child.sensitive = i == index
 
     def _on_value_changed(self, setting, value):
-        if value != self.gconf_client.get(setting.gconf_key):
-            val = GConf.Value.new(setting.gconf_type)
-            setting.set_gconf_value(val)
-            self.gconf_client.set(setting.gconf_key, val)
+        if value != \
+                self._gsettings.get_value(setting.gsettings_key).unpack():
+            self._gsettings.set_value(setting.gsettings_key, setting.gvariant)
             self._change_dependant_sensitivity(setting)
 
-    def _gconf_setting_changed_cb(self, client, connection_id, entry, data):
-        setting, handler_id = data
-        new_value = client.get_value(setting.gconf_key)
+    def _gsettings_changed_cb(self, gsettings, key):
+        setting = getattr(self, key.replace('-', '_'))
+        new_value = gsettings.get_value(key).unpack()
         if setting.value != new_value:
-            setting.handler_block(handler_id)
+            setting.hush = True
             setting.value = new_value
-            setting.handler_unblock(handler_id)
+            setting.hush = False
 
     def __call__(self):
         return self



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]