diff options
author | Rodrigo Moya <rodrigo@gnome-db.org> | 2010-10-22 17:22:13 +0200 |
---|---|---|
committer | Rodrigo Moya <rodrigo@gnome-db.org> | 2010-10-22 17:22:13 +0200 |
commit | e247aa0f42b1f4ecc301a1babd52f9e6a7849368 (patch) | |
tree | ffe64dc9f6adaf53c07e5abebc6f04c2e9ab4e43 | |
parent | 54607e1aa4fe46bcea9983d6874f484832c402ac (diff) | |
download | gnome-settings-daemon-e247aa0f42b1f4ecc301a1babd52f9e6a7849368.tar.gz |
gconf: Listen to GSettings changes and propagate them to GConf, only one-way
-rw-r--r-- | plugins/gconf/conf-watcher.c | 80 | ||||
-rw-r--r-- | plugins/gconf/conf-watcher.h | 6 | ||||
-rw-r--r-- | plugins/gconf/gsd-gconf-manager.c | 2 |
3 files changed, 88 insertions, 0 deletions
diff --git a/plugins/gconf/conf-watcher.c b/plugins/gconf/conf-watcher.c index 32e572ae..99a148db 100644 --- a/plugins/gconf/conf-watcher.c +++ b/plugins/gconf/conf-watcher.c @@ -28,6 +28,12 @@ conf_watcher_finalize (GObject *object) { ConfWatcher *watcher = CONF_WATCHER (object); + if (watcher->settings != NULL) + g_object_unref (watcher->settings); + + if (watcher->conf_client != NULL) + g_object_unref (watcher->conf_client); + if (watcher->settings_id != NULL) g_free (watcher->settings_id); @@ -50,6 +56,76 @@ conf_watcher_init (ConfWatcher *watcher) { } +static void +settings_changed_cb (GSettings *settings, + const gchar *key, + ConfWatcher *watcher) +{ + const gchar *gconf_key_name; + + gconf_key_name = g_hash_table_lookup (watcher->keys_hash, key); + if (gconf_key_name != NULL) { + GVariant *value; + + value = g_settings_get_value (settings, key); + if (g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) { + gconf_client_set_bool (watcher->conf_client, + gconf_key_name, + g_variant_get_boolean (value), + NULL); + } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_BYTE) || + g_variant_is_of_type (value, G_VARIANT_TYPE_INT16) || + g_variant_is_of_type (value, G_VARIANT_TYPE_UINT16) || + g_variant_is_of_type (value, G_VARIANT_TYPE_INT32) || + g_variant_is_of_type (value, G_VARIANT_TYPE_UINT32) || + g_variant_is_of_type (value, G_VARIANT_TYPE_INT64) || + g_variant_is_of_type (value, G_VARIANT_TYPE_UINT64)) { + gconf_client_set_int (watcher->conf_client, + gconf_key_name, + g_settings_get_int (settings, key), + NULL); + } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) { + gconf_client_set_string (watcher->conf_client, + gconf_key_name, + g_variant_get_string (value, NULL), + NULL); + } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_DOUBLE)) { + gconf_client_set_float (watcher->conf_client, + gconf_key_name, + g_variant_get_double (value), + NULL); + } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY)) { + const gchar **items; + gsize len, i; + GSList *gconf_list = NULL; + + items = g_variant_get_strv (value, &len); + for (i = 0; i < len; i++) { + gconf_list = g_slist_append (gconf_list, (gpointer) items[i]); + } + + gconf_client_set_list (watcher->conf_client, + gconf_key_name, + GCONF_VALUE_STRING, + gconf_list, + NULL); + + g_slist_free (gconf_list); + g_free (items); + } + } +} + +static void +setup_watcher (ConfWatcher *watcher) +{ + watcher->settings = g_settings_new (watcher->settings_id); + g_signal_connect (watcher->settings, "changed", + G_CALLBACK (settings_changed_cb), watcher); + + watcher->conf_client = gconf_client_get_default (); +} + ConfWatcher * conf_watcher_new (const gchar *settings_id, GHashTable *keys_hash) { @@ -60,5 +136,9 @@ conf_watcher_new (const gchar *settings_id, GHashTable *keys_hash) watcher = g_object_new (TYPE_CONF_WATCHER, NULL); + watcher->settings_id = g_strdup (settings_id); + watcher->keys_hash = keys_hash; + setup_watcher (watcher); + return watcher; } diff --git a/plugins/gconf/conf-watcher.h b/plugins/gconf/conf-watcher.h index d86ffebb..ffe5544c 100644 --- a/plugins/gconf/conf-watcher.h +++ b/plugins/gconf/conf-watcher.h @@ -22,6 +22,8 @@ #define __CONF_WATCHER_H #include <glib-object.h> +#include <gio/gio.h> +#include <gconf/gconf-client.h> G_BEGIN_DECLS @@ -37,6 +39,10 @@ typedef struct ConfWatcherPrivate ConfWatcherPrivate; typedef struct { GObject parent; + + /* Private data */ + GSettings *settings; + GConfClient *conf_client; gchar *settings_id; GHashTable *keys_hash; } ConfWatcher; diff --git a/plugins/gconf/gsd-gconf-manager.c b/plugins/gconf/gsd-gconf-manager.c index fa57963b..ac78e564 100644 --- a/plugins/gconf/gsd-gconf-manager.c +++ b/plugins/gconf/gsd-gconf-manager.c @@ -81,6 +81,8 @@ gsd_gconf_manager_start (GsdGconfManager *manager, GError **error) GDir *convertdir; gboolean result = FALSE; + manager->priv->conf_watchers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); + /* Read all conversion files from GCONF_SETTINGS_CONVERTDIR */ convertdir = g_dir_open (GCONF_SETTINGS_CONVERTDIR, 0, error); if (convertdir) { |