diff options
author | Eitan Isaacson <eitan@monotonous.org> | 2011-03-07 00:47:48 -0800 |
---|---|---|
committer | Eitan Isaacson <eitan@monotonous.org> | 2011-03-07 00:47:48 -0800 |
commit | 0aa3ff942a1a7a7c3229703c9878ec416731c2df (patch) | |
tree | c7df7ff055d7918d9bd20d7c4a2de8b2d90fb79d | |
parent | f9d4f7bcf608810f977102ccb6bb32f98479eec6 (diff) | |
download | caribou-0aa3ff942a1a7a7c3229703c9878ec416731c2df.tar.gz |
Generate GSettings schema instead of GConf schema.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | caribou/common/setting_types.py | 52 | ||||
-rw-r--r-- | caribou/common/settings.py | 37 | ||||
-rw-r--r-- | caribou/common/settings_manager.py | 1 | ||||
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | data/Makefile.am | 27 | ||||
-rw-r--r-- | po/POTFILES.skip | 2 |
7 files changed, 45 insertions, 83 deletions
@@ -24,3 +24,4 @@ data/caribou.desktop po/.intltool-merge-cache data/caribou.schemas data/caribou.schemas.in +data/org.gnome.caribou.gschema.* diff --git a/caribou/common/setting_types.py b/caribou/common/setting_types.py index 5b8aa95..130a0b5 100644 --- a/caribou/common/setting_types.py +++ b/caribou/common/setting_types.py @@ -1,7 +1,5 @@ import gobject -from gi.repository import GConf - -GCONF_DIR="/apps/caribou/osk/" +from gi.repository import GLib ENTRY_DEFAULT=0 ENTRY_COMBO=1 @@ -56,7 +54,7 @@ class SettingsGroup(Setting): pass class ValueSetting(Setting): - gconf_type = GConf.ValueType.INVALID + variant_type = '' entry_type=ENTRY_DEFAULT def __init__(self, name, label, default, short_desc="", long_desc="", allowed=[], entry_type=ENTRY_DEFAULT, sensitive=None, @@ -80,61 +78,33 @@ class ValueSetting(Setting): @value.setter def value(self, val): - _val = self.convert_value(self._from_gconf_value(val)) + _val = self.convert_value(val.unpack()) 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) @property - def gconf_key(self): - return GCONF_DIR + self.name + def gsettings_key(self): + return self.name.replace('_', '-') @property def is_true(self): return bool(self.value) @property - 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() + def gvariant(self): + return GLib.Variant(self.variant_type, self.value) class BooleanSetting(ValueSetting): - gconf_type = GConf.ValueType.BOOL + variant_type = 'b' entry_type = ENTRY_CHECKBOX def convert_value(self, val): # Almost anything could be a boolean. return bool(val) - @property - def gconf_default(self): - str(self.default).lower() - class IntegerSetting(ValueSetting): - gconf_type = GConf.ValueType.INT + variant_type = 'i' entry_type = ENTRY_SPIN def __init__(self, *args, **kwargs): self.min = kwargs.pop('min', gobject.G_MININT) @@ -145,7 +115,7 @@ class IntegerSetting(ValueSetting): return int(val) class FloatSetting(ValueSetting): - gconf_type = GConf.ValueType.FLOAT + variant_type = 'd' entry_type = ENTRY_SPIN def __init__(self, *args, **kwargs): self.min = kwargs.pop('min', gobject.G_MINFLOAT) @@ -156,7 +126,7 @@ class FloatSetting(ValueSetting): return float(val) class StringSetting(ValueSetting): - gconf_type = GConf.ValueType.STRING + variant_type = 's' def convert_value(self, val): return str(val) diff --git a/caribou/common/settings.py b/caribou/common/settings.py index 09a23a9..b5df28e 100644 --- a/caribou/common/settings.py +++ b/caribou/common/settings.py @@ -124,15 +124,19 @@ settings = SettingsGroup("_top", "", [ ]) if __name__ == "__main__": + from gi.repository import GLib + class SchemasMaker: def create_schemas(self): doc = xml.dom.minidom.Document() - gconfschemafile = doc.createElement('gconfschemafile') - schemalist = doc.createElement('schemalist') - gconfschemafile.appendChild(schemalist) - self._create_schema(settings, doc, schemalist) + schemafile = doc.createElement('schemalist') + schema = doc.createElement('schema') + schema.setAttribute("id", "org.gnome.caribou") + schema.setAttribute("path", "/apps/caribou/osk/") + schemafile.appendChild(schema) + self._create_schema(settings, doc, schema) - self._pretty_xml(gconfschemafile) + self._pretty_xml(schemafile) def _attribs(self, e): if not e.attributes.items(): @@ -159,21 +163,16 @@ if __name__ == "__main__": element.appendChild(el) def _create_schema(self, setting, doc, schemalist): - if hasattr(setting, 'gconf_key'): - schema = doc.createElement('schema') - schemalist.appendChild(schema) - self._append_children_element_value_pairs( - doc, schema, [('key', '/schemas' + setting.gconf_key), - ('applyto', setting.gconf_key), - ('owner', 'caribou'), - ('type', setting.gconf_type.value_nick), - ('default', setting.gconf_default)]) - locale = doc.createElement('locale') - locale.setAttribute('name', 'C') - schema.appendChild(locale) + if hasattr(setting, 'gsettings_key'): + key = doc.createElement('key') + key.setAttribute('name', setting.gsettings_key) + key.setAttribute('type', setting.variant_type) + schemalist.appendChild(key) self._append_children_element_value_pairs( - doc, locale, [('short', setting.short_desc), - ('long', setting.long_desc)]) + doc, key, [('default', + getattr(setting.gvariant, "print")(False)), + ('_summary', setting.short_desc), + ('_description', setting.long_desc)]) for s in setting: self._create_schema(s, doc, schemalist) diff --git a/caribou/common/settings_manager.py b/caribou/common/settings_manager.py index 37d178b..c073fef 100644 --- a/caribou/common/settings_manager.py +++ b/caribou/common/settings_manager.py @@ -62,7 +62,6 @@ class _SettingsManager(object): def _on_value_changed(self, setting, 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) diff --git a/configure.ac b/configure.ac index c8b5830..25f5b7a 100644 --- a/configure.ac +++ b/configure.ac @@ -20,12 +20,14 @@ AC_PATH_PROG(GCONFTOOL, gconftool-2) AM_GCONF_SOURCE_2 dnl == Library dependencies == +PYGOBJECT_REQUIRED=2.27.92 GTK_REQUIRED=2.91.8 CLUTTER_REQUIRED=1.5.11 PKG_CHECK_MODULES(CARIBOU, [ - gtk+-3.0 >= $GTK_REQUIRED, - clutter-1.0 >= $CLUTTER_REQUIRED]) + pygobject-2.0 >= $PYGOBJECT_REQUIRED, + gtk+-3.0 >= $GTK_REQUIRED, + clutter-1.0 >= $CLUTTER_REQUIRED]) AC_SUBST(CARIBOU_CFLAGS) AC_SUBST(CARIBOU_LIBS) @@ -35,6 +37,8 @@ AC_SUBST(GETTEXT_PACKAGE) AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [The gettext package]) AM_GLIB_GNU_GETTEXT +GLIB_GSETTINGS + dnl == intltool check == IT_PROG_INTLTOOL([0.35.0]) diff --git a/data/Makefile.am b/data/Makefile.am index ffdaa39..afe1950 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,9 +1,9 @@ SUBDIRS = keyboards -schemasdir = $(GCONF_SCHEMA_FILE_DIR) -schemas_in_files = caribou.schemas.in -schemas_DATA = $(schemas_in_files:.schemas.in=.schemas) -@INTLTOOL_SCHEMAS_RULE@ +@GSETTINGS_RULES@ +@INTLTOOL_XML_NOMERGE_RULE@ +gsettings_schemas_in_files = org.gnome.caribou.gschema.xml.in +gsettings_SCHEMAS = $(gsettings_schemas_in_files:.gschema.xml.in=.gschema.xml) desktopdir = $(datadir)/applications desktop_in_files = caribou.desktop.in @@ -12,20 +12,9 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) EXTRA_DIST = $(desktop_in_files) -caribou.schemas.in: $(top_srcdir)/caribou/common/settings.py - PYTHONPATH=$(top_srcdir) $(PYTHON) $< > $@ +org.gnome.caribou.gschema.xml.in: $(top_srcdir)/caribou/common/settings.py + PYTHONPATH=${PYTHONPATH}:$(top_srcdir) $(PYTHON) $< > $@ CLEANFILES = $(desktop_DATA) \ - $(schemas_in_files) \ - $(schemas_DATA) - -# installation of schemas -if GCONF_SCHEMAS_INSTALL -install-data-hook: - GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \ - $(GCONFTOOL) --makefile-install-rule $(schemas_DATA) - -uninstall-hook: - GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \ - $(GCONFTOOL) --makefile-uninstall-rule $(schemas_DATA) -endif + $(gsettings_schemas_in_files) \ + $(gsettings_SCHEMAS) diff --git a/po/POTFILES.skip b/po/POTFILES.skip index e3c0a47..7386c06 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -1 +1 @@ -data/caribou.schemas.in +data/org.gnome.caribou.gschema.xml.in |