GConfig Plans and Design
note: these are my design notes of december 2006, when I started working on gconfig design. gconfig is not exactly like this anymore, and only the tenets are the important part. EmmanueleBassi
you
configuration object path (like D-Bus paths): namespace:/path/to/object
get two preferences from the applications:/org/gnome/Test configuration object: set a preference of the applications:/org/gnome/Test configuration object, with direct error reporting:
gconfig resource file (similar to gtkrc, parsed by GScanner)
Design tenets
need a schema Assumptions
Low level API
API usage examples
GConfigFactory *factory;
gchar *foo;
gint bar;
factory = g_config_get_applications_factory ("/org/gnome/Test", "test.schemas");
g_config_factory_get (factory, "foo", &foo, "bar", &bar, NULL);
g_object_unref (factory);
if (!g_config_factory_set_preference (factory, "bar", new_bar))
{
GError *error;
g_config_factory_get_error (factory, &error);
g_warning ("Error: %s", error->message);
g_error_free (error);
}
static void
on_error_cb (GConfigFactory *factory,
const GError *error,
gpointer user_data)
{
...
}
...
g_signal_connect (factory, "error", G_CALLBACK (on_error_cb), NULL);
g_config_factory_set (factory, "bar", new_bar, NULL);
static void
on_foo_changed_cb (GConfigFactory *factory,
const gchar *preference, /* "foo" */
GConfigSchema *schema,
gpointer user_data)
{
gchar *foo;
g_config_factory_get (factory, preference, &foo, NULL);
}
...
g_signal_connect (factory, "changed::foo", G_CALLBACK (on_foo_changed_cb), NULL);
Configuration
namespace "applications" {
readable = TRUE
writable = TRUE
backend "file" {
base_path "$HOME/.gconfig/applications"
}
}
namespace "system" {
readable = TRUE
writable = TRUE
backend "bdb" {
base_path "$HOME/.gconfig/system"
}
}
schema "org.gnome.Foo" {
# override the file containing the schema
path "/etc/gconfig/local/our-foo"
}
schema "org.gnome.Bar" {
# override a preference - a schema for org.gnome.Bar/baz *must* exist
preference "baz" {
type = "int"
value = 42
}
}
Schemas
Backends
Namespaces
applications - name says it all Lockdown policy
writable will make any further call for setting a preference for that object fail