[gconf] [gsettings] Reorganize code
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gconf] [gsettings] Reorganize code
- Date: Fri, 16 Apr 2010 13:10:43 +0000 (UTC)
commit e374f886e6f225375922de8c9f0cf1da8daf4613
Author: Vincent Untz <vuntz gnome org>
Date: Fri Apr 16 01:06:42 2010 -0400
[gsettings] Reorganize code
gsettings/gconfsettingsbackend.c | 351 ++++++++++++++++++++------------------
1 files changed, 186 insertions(+), 165 deletions(-)
---
diff --git a/gsettings/gconfsettingsbackend.c b/gsettings/gconfsettingsbackend.c
index 7cae64b..b8b6458 100644
--- a/gsettings/gconfsettingsbackend.c
+++ b/gsettings/gconfsettingsbackend.c
@@ -60,6 +60,187 @@ struct _GConfSettingsBackendNotifier
GList *subpaths;
};
+static void
+gconf_settings_backend_notified (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ GConfSettingsBackend *gconf);
+
+/**********************\
+ * Notifiers handling *
+\**********************/
+
+static GConfSettingsBackendNotifier *
+gconf_settings_backend_find_notifier_or_parent (GConfSettingsBackend *gconf,
+ const gchar *path)
+{
+ GConfSettingsBackendNotifier *parent;
+ GList *l;
+
+ l = gconf->priv->notifiers;
+ parent = NULL;
+
+ while (l != NULL)
+ {
+ GConfSettingsBackendNotifier *notifier;
+ notifier = l->data;
+ if (g_str_equal (path, notifier->path))
+ return notifier;
+ if (g_str_has_prefix (path, notifier->path))
+ {
+ parent = notifier;
+ l = parent->subpaths;
+ continue;
+ }
+ if (g_str_has_prefix (notifier->path, path))
+ break;
+
+ l = l->next;
+ }
+
+ return parent;
+}
+
+static void
+gconf_settings_backend_free_notifier (GConfSettingsBackendNotifier *notifier,
+ GConfSettingsBackend *gconf)
+{
+ if (notifier->path)
+ g_free (notifier->path);
+ notifier->path = NULL;
+
+ if (notifier->notify_id)
+ gconf_client_notify_remove (gconf->priv->client, notifier->notify_id);
+ notifier->notify_id = 0;
+
+ g_list_foreach (notifier->subpaths, (GFunc) gconf_settings_backend_free_notifier, gconf);
+ g_list_free (notifier->subpaths);
+ notifier->subpaths = NULL;
+
+ g_slice_free (GConfSettingsBackendNotifier, notifier);
+}
+
+/* Returns: TRUE if the notifier was created, FALSE if it was already existing. */
+static gboolean
+gconf_settings_backend_add_notifier (GConfSettingsBackend *gconf,
+ const gchar *path)
+{
+ GConfSettingsBackendNotifier *n_or_p;
+ GConfSettingsBackendNotifier *notifier;
+ GList *siblings;
+ GList *l;
+
+ n_or_p = gconf_settings_backend_find_notifier_or_parent (gconf, path);
+
+ if (n_or_p && g_str_equal (path, n_or_p->path))
+ {
+ n_or_p->refcount += 1;
+ return FALSE;
+ }
+
+ notifier = g_slice_new0 (GConfSettingsBackendNotifier);
+ notifier->parent = n_or_p;
+ notifier->path = g_strdup (path);
+ notifier->refcount = 1;
+
+ if (notifier->parent == NULL)
+ notifier->notify_id = gconf_client_notify_add (gconf->priv->client, path,
+ (GConfClientNotifyFunc) gconf_settings_backend_notified, gconf,
+ NULL, NULL);
+ else
+ notifier->notify_id = 0;
+
+ /* Move notifiers living at the same level but that are subpaths below this
+ * new notifier, removing their notify handler if necessary. */
+ if (notifier->parent)
+ siblings = notifier->parent->subpaths;
+ else
+ siblings = gconf->priv->notifiers;
+
+ l = siblings;
+ while (l != NULL)
+ {
+ GConfSettingsBackendNotifier *sibling;
+ GList *next;
+
+ sibling = l->data;
+ next = l->next;
+
+ if (g_str_has_prefix (sibling->path, notifier->path))
+ {
+ if (sibling->notify_id)
+ {
+ gconf_client_notify_remove (gconf->priv->client,
+ sibling->notify_id);
+ sibling->notify_id = 0;
+ }
+
+ siblings = g_list_remove_link (siblings, l);
+ l->next = notifier->subpaths;
+ notifier->subpaths = l;
+ }
+
+ l = next;
+ }
+
+ if (notifier->parent)
+ notifier->parent->subpaths = siblings;
+ else
+ gconf->priv->notifiers = siblings;
+
+ return TRUE;
+}
+
+/* Returns: TRUE if the notifier was removed, FALSE if it is still referenced. */
+static gboolean
+gconf_settings_backend_remove_notifier (GConfSettingsBackend *gconf,
+ const gchar *path)
+{
+ GConfSettingsBackendNotifier *notifier;
+
+ notifier = gconf_settings_backend_find_notifier_or_parent (gconf, path);
+
+ g_assert (g_str_equal (path, notifier->path));
+
+ notifier->refcount -= 1;
+
+ if (notifier->refcount > 0)
+ return FALSE;
+
+ /* Move subpaths to the parent, and add a notify handler for each of them if
+ * they have no parent anymore. */
+ if (notifier->parent)
+ notifier->parent->subpaths = g_list_concat (notifier->parent->subpaths,
+ notifier->subpaths);
+ else
+ {
+ GList *l;
+
+ for (l = notifier->subpaths; l != NULL; l = l->next)
+ {
+ GConfSettingsBackendNotifier *child = l->data;
+ child->notify_id = gconf_client_notify_add (gconf->priv->client, child->path,
+ (GConfClientNotifyFunc) gconf_settings_backend_notified, gconf,
+ NULL, NULL);
+ }
+
+ gconf->priv->notifiers = g_list_concat (gconf->priv->notifiers,
+ notifier->subpaths);
+ }
+
+ notifier->subpaths = NULL;
+
+ gconf_settings_backend_free_notifier (notifier, gconf);
+
+ return TRUE;
+}
+
+
+
+/***************************\
+ * GConfValue <=> GVariant *
+\***************************/
+
static gboolean
gconf_settings_backend_simple_gconf_value_type_is_compatible (GConfValueType type,
const GVariantType *expected_type)
@@ -421,6 +602,11 @@ gconf_settings_backend_gvariant_to_gconf_value (GVariant *value)
return gconf_value;
}
+
+/**************************\
+ * Backend implementation *
+\**************************/
+
static GVariant *
gconf_settings_backend_read (GSettingsBackend *backend,
const gchar *key,
@@ -630,171 +816,6 @@ gconf_settings_backend_notified (GConfClient *client,
g_settings_backend_changed (G_SETTINGS_BACKEND (gconf), entry->key, NULL);
}
-static GConfSettingsBackendNotifier *
-gconf_settings_backend_find_notifier_or_parent (GConfSettingsBackend *gconf,
- const gchar *path)
-{
- GConfSettingsBackendNotifier *parent;
- GList *l;
-
- l = gconf->priv->notifiers;
- parent = NULL;
-
- while (l != NULL)
- {
- GConfSettingsBackendNotifier *notifier;
- notifier = l->data;
- if (g_str_equal (path, notifier->path))
- return notifier;
- if (g_str_has_prefix (path, notifier->path))
- {
- parent = notifier;
- l = parent->subpaths;
- continue;
- }
- if (g_str_has_prefix (notifier->path, path))
- break;
-
- l = l->next;
- }
-
- return parent;
-}
-
-static void
-gconf_settings_backend_free_notifier (GConfSettingsBackendNotifier *notifier,
- GConfSettingsBackend *gconf)
-{
- if (notifier->path)
- g_free (notifier->path);
- notifier->path = NULL;
-
- if (notifier->notify_id)
- gconf_client_notify_remove (gconf->priv->client, notifier->notify_id);
- notifier->notify_id = 0;
-
- g_list_foreach (notifier->subpaths, (GFunc) gconf_settings_backend_free_notifier, gconf);
- g_list_free (notifier->subpaths);
- notifier->subpaths = NULL;
-
- g_slice_free (GConfSettingsBackendNotifier, notifier);
-}
-
-/* Returns: TRUE if the notifier was created, FALSE if it was already existing. */
-static gboolean
-gconf_settings_backend_add_notifier (GConfSettingsBackend *gconf,
- const gchar *path)
-{
- GConfSettingsBackendNotifier *n_or_p;
- GConfSettingsBackendNotifier *notifier;
- GList *siblings;
- GList *l;
-
- n_or_p = gconf_settings_backend_find_notifier_or_parent (gconf, path);
-
- if (n_or_p && g_str_equal (path, n_or_p->path))
- {
- n_or_p->refcount += 1;
- return FALSE;
- }
-
- notifier = g_slice_new0 (GConfSettingsBackendNotifier);
- notifier->parent = n_or_p;
- notifier->path = g_strdup (path);
- notifier->refcount = 1;
-
- if (notifier->parent == NULL)
- notifier->notify_id = gconf_client_notify_add (gconf->priv->client, path,
- (GConfClientNotifyFunc) gconf_settings_backend_notified, gconf,
- NULL, NULL);
- else
- notifier->notify_id = 0;
-
- /* Move notifiers living at the same level but that are subpaths below this
- * new notifier, removing their notify handler if necessary. */
- if (notifier->parent)
- siblings = notifier->parent->subpaths;
- else
- siblings = gconf->priv->notifiers;
-
- l = siblings;
- while (l != NULL)
- {
- GConfSettingsBackendNotifier *sibling;
- GList *next;
-
- sibling = l->data;
- next = l->next;
-
- if (g_str_has_prefix (sibling->path, notifier->path))
- {
- if (sibling->notify_id)
- {
- gconf_client_notify_remove (gconf->priv->client,
- sibling->notify_id);
- sibling->notify_id = 0;
- }
-
- siblings = g_list_remove_link (siblings, l);
- l->next = notifier->subpaths;
- notifier->subpaths = l;
- }
-
- l = next;
- }
-
- if (notifier->parent)
- notifier->parent->subpaths = siblings;
- else
- gconf->priv->notifiers = siblings;
-
- return TRUE;
-}
-
-/* Returns: TRUE if the notifier was removed, FALSE if it is still referenced. */
-static gboolean
-gconf_settings_backend_remove_notifier (GConfSettingsBackend *gconf,
- const gchar *path)
-{
- GConfSettingsBackendNotifier *notifier;
-
- notifier = gconf_settings_backend_find_notifier_or_parent (gconf, path);
-
- g_assert (g_str_equal (path, notifier->path));
-
- notifier->refcount -= 1;
-
- if (notifier->refcount > 0)
- return FALSE;
-
- /* Move subpaths to the parent, and add a notify handler for each of them if
- * they have no parent anymore. */
- if (notifier->parent)
- notifier->parent->subpaths = g_list_concat (notifier->parent->subpaths,
- notifier->subpaths);
- else
- {
- GList *l;
-
- for (l = notifier->subpaths; l != NULL; l = l->next)
- {
- GConfSettingsBackendNotifier *child = l->data;
- child->notify_id = gconf_client_notify_add (gconf->priv->client, child->path,
- (GConfClientNotifyFunc) gconf_settings_backend_notified, gconf,
- NULL, NULL);
- }
-
- gconf->priv->notifiers = g_list_concat (gconf->priv->notifiers,
- notifier->subpaths);
- }
-
- notifier->subpaths = NULL;
-
- gconf_settings_backend_free_notifier (notifier, gconf);
-
- return TRUE;
-}
-
static void
gconf_settings_backend_subscribe (GSettingsBackend *backend,
const gchar *name)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]