diff options
author | Ali Abdallah <ali@xfce.org> | 2018-07-14 00:02:33 +0200 |
---|---|---|
committer | Ali Abdallah <ali@xfce.org> | 2018-07-14 00:02:33 +0200 |
commit | ff8de61d236039fa2619f1ec8997965db338bbc9 (patch) | |
tree | fd84b647ddb632f296a213955fc9e2c1b3f094fc /gsettings-backend | |
parent | 4864bed3de435a1bc87c2f9b263476465c406e19 (diff) | |
download | xfconf-ff8de61d236039fa2619f1ec8997965db338bbc9.tar.gz |
Handle subscribe/unsubscribe GSettings interface method.
Diffstat (limited to 'gsettings-backend')
-rw-r--r-- | gsettings-backend/xfconf-gsettings-backend.c | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/gsettings-backend/xfconf-gsettings-backend.c b/gsettings-backend/xfconf-gsettings-backend.c index deba52a..1218c79 100644 --- a/gsettings-backend/xfconf-gsettings-backend.c +++ b/gsettings-backend/xfconf-gsettings-backend.c @@ -36,6 +36,7 @@ struct _XfconfGsettingsBackend XfconfChannel *channel; GHashTable *changed_prop; + GHashTable *subscribed_prop; }; G_DEFINE_TYPE (XfconfGsettingsBackend, xfconf_gsettings_backend, G_TYPE_SETTINGS_BACKEND); @@ -48,17 +49,33 @@ xfconf_gsettings_backend_property_changed_cb (XfconfGsettingsBackend *self, gpointer origin_tag; gboolean found; + /* Look if this property has been changed by calling the write method below */ found = g_hash_table_lookup_extended (self->changed_prop, property, NULL, &origin_tag); if (found) { /* Emit the changed signal */ g_debug ("Emitting property changed signal '%s'\n", property); g_settings_backend_changed ((GSettingsBackend*)self, property, origin_tag); + g_hash_table_remove (self->changed_prop, property); } else { - g_warning ("Changed property '%s' not expected!", property); + /* Check to see if the client subscribed on that property */ + GList *keys; + GList *l; + + keys = g_hash_table_get_keys (self->subscribed_prop); + for (l = keys; l; l=l->next) { + if (g_str_has_prefix (property, (gchar*)l->data)) { + found = TRUE; + g_debug ("Emitting property changed signal '%s'\n", property); + g_settings_backend_changed ((GSettingsBackend*)self, property, NULL); + break; + } + } + g_list_free(keys); } - g_hash_table_remove (self->changed_prop, property); + if (!found) + g_warning ("Changed property '%s' not expected!", property); } static GVariant * @@ -159,6 +176,39 @@ xfconf_gsettings_backend_write_tree (GSettingsBackend *backend, return TRUE; } +static void +xfconf_gsettings_backend_subscribe (GSettingsBackend *backend, + const char *name) +{ + XfconfGsettingsBackend *self; + + self = XFCONF_GSETTINGS_BACKEND(backend); + + g_debug ("Subscribe on property '%s'\n", name); + + g_hash_table_replace (self->subscribed_prop, g_strdup(name), g_strdup(name)); +} + +static void +xfconf_gsettings_backend_unsubscribe (GSettingsBackend *backend, + const char *name) +{ + XfconfGsettingsBackend *self; + + self = XFCONF_GSETTINGS_BACKEND(backend); + + g_debug ("Unsubscribe from property '%s'\n", name); + + g_hash_table_remove (self->subscribed_prop, name); +} + + +static gboolean +xfconf_gsettings_backend_has_prefix (gconstpointer v1, + gconstpointer v2) +{ + return g_str_has_prefix ((const gchar*)v1, (const gchar*)v2); +} static void xfconf_gsettings_backend_finalize (XfconfGsettingsBackend *self) @@ -167,6 +217,8 @@ xfconf_gsettings_backend_finalize (XfconfGsettingsBackend *self) g_hash_table_destroy (self->changed_prop); + g_hash_table_destroy (self->subscribed_prop); + G_OBJECT_CLASS(xfconf_gsettings_backend_parent_class)->finalize((GObject*)self); } @@ -182,6 +234,9 @@ xfconf_gsettings_backend_init (XfconfGsettingsBackend *self) self->changed_prop = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + self->subscribed_prop = g_hash_table_new_full (g_str_hash, xfconf_gsettings_backend_has_prefix, + g_free, g_free); + g_signal_connect_swapped (self->channel, "property-changed", G_CALLBACK (xfconf_gsettings_backend_property_changed_cb), self); } @@ -197,6 +252,8 @@ xfconf_gsettings_backend_class_init (XfconfGsettingsBackendClass *klass) gsettings_class->get_writable = xfconf_gsettings_backend_get_writable; gsettings_class->write_tree = xfconf_gsettings_backend_write_tree; gsettings_class->write = xfconf_gsettings_backend_write; + gsettings_class->subscribe = xfconf_gsettings_backend_subscribe; + gsettings_class->unsubscribe = xfconf_gsettings_backend_unsubscribe; object_class->finalize = (void (*) (GObject *object)) xfconf_gsettings_backend_finalize; } |