[glib/new-gsettings] delayed backend stuff
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/new-gsettings] delayed backend stuff
- Date: Fri, 16 Apr 2010 05:23:33 +0000 (UTC)
commit 3694f979100b1a2d16eb33695364ca0c1b4ae87e
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Apr 16 01:22:57 2010 -0400
delayed backend stuff
gio/gdelayedsettingsbackend.c | 255 +++++++++++++++++++----------------------
gio/gdelayedsettingsbackend.h | 8 +-
gio/gsettings.c | 44 +++-----
gio/gsettings.h | 4 +-
gio/tests/gsettings.c | 9 +-
5 files changed, 142 insertions(+), 178 deletions(-)
---
diff --git a/gio/gdelayedsettingsbackend.c b/gio/gdelayedsettingsbackend.c
index 469b2c7..cd50b9d 100644
--- a/gio/gdelayedsettingsbackend.c
+++ b/gio/gdelayedsettingsbackend.c
@@ -19,27 +19,32 @@
#include "gioalias.h"
-enum
-{
- PROP_NONE,
- PROP_BACKEND,
- PROP_HAS_UNAPPLIED
-};
-
struct _GDelayedSettingsBackendPrivate
{
GSettingsBackend *backend;
- guint writable_changed_handler_id;
- guint keys_changed_handler_id;
- guint changed_handler_id;
GTree *delayed;
+ gpointer owner;
};
G_DEFINE_TYPE (GDelayedSettingsBackend,
g_delayed_settings_backend,
G_TYPE_SETTINGS_BACKEND)
-static void
+static GVariant *
+g_delayed_settings_backend_read (GSettingsBackend *backend,
+ const gchar *key,
+ const GVariantType *expected_type)
+{
+ GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
+ GVariant *result;
+
+ if ((result = g_tree_lookup (delayed->priv->delayed, key)))
+ return g_variant_ref (result);
+
+ return g_settings_backend_read (delayed->priv->backend,
+ key, expected_type);
+}
+static gboolean
g_delayed_settings_backend_write (GSettingsBackend *backend,
const gchar *key,
GVariant *value,
@@ -53,8 +58,10 @@ g_delayed_settings_backend_write (GSettingsBackend *backend,
g_variant_ref_sink (value));
g_settings_backend_changed (backend, key, origin_tag);
- if (was_empty)
- g_object_notify (G_OBJECT (delayed), "has-unapplied");
+ if (was_empty && delayed->priv->owner)
+ g_object_notify (delayed->priv->owner, "has-unapplied");
+
+ return TRUE;
}
static gboolean
@@ -66,7 +73,7 @@ add_to_tree (gpointer key,
return FALSE;
}
-static void
+static gboolean
g_delayed_settings_backend_write_keys (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag)
@@ -80,25 +87,57 @@ g_delayed_settings_backend_write_keys (GSettingsBackend *backend,
g_settings_backend_changed_tree (backend, tree, origin_tag);
- if (was_empty)
- g_object_notify (G_OBJECT (delayed), "has-unapplied");
+ if (was_empty && delayed->priv->owner)
+ g_object_notify (delayed->priv->owner, "has-unapplied");
+
+ return TRUE;
}
-static GVariant *
-g_delayed_settings_backend_read (GSettingsBackend *backend,
- const gchar *key,
- const GVariantType *expected_type)
+static gboolean
+g_delayed_settings_backend_get_writable (GSettingsBackend *backend,
+ const gchar *name)
{
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
- GVariant *result;
- if ((result = g_tree_lookup (delayed->priv->delayed, key)))
- return g_variant_ref (result);
+ return g_settings_backend_get_writable (delayed->priv->backend, name);
+}
- return g_settings_backend_read (delayed->priv->backend,
- key, expected_type);
+static void
+g_delayed_settings_backend_reset (GSettingsBackend *backend,
+ const gchar *key,
+ gpointer origin_tag)
+{
+ /* deal with this... */
+}
+
+static void
+g_delayed_settings_backend_reset_path (GSettingsBackend *backend,
+ const gchar *path,
+ gpointer origin_tag)
+{
+ /* deal with this... */
+}
+
+static void
+g_delayed_settings_backend_subscribe (GSettingsBackend *backend,
+ const char *name)
+{
+ GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
+
+ g_settings_backend_subscribe (delayed->priv->backend, name);
}
+static void
+g_delayed_settings_backend_unsubscribe (GSettingsBackend *backend,
+ const char *name)
+{
+ GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
+
+ g_settings_backend_unsubscribe (delayed->priv->backend, name);
+}
+
+
+/* method calls */
gboolean
g_delayed_settings_backend_get_has_unapplied (GDelayedSettingsBackend *delayed)
{
@@ -138,78 +177,23 @@ g_delayed_settings_backend_revert (GDelayedSettingsBackend *delayed)
}
}
-static gboolean
-g_delayed_settings_backend_get_writable (GSettingsBackend *backend,
- const gchar *name)
-{
- GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
-
- return g_settings_backend_get_writable (delayed->priv->backend, name);
-}
-
-static void
-g_delayed_settings_backend_subscribe (GSettingsBackend *base,
- const char *name)
-{
-}
-
-static void
-g_delayed_settings_backend_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (object);
-
- switch (prop_id)
- {
- gboolean has;
-
- case PROP_HAS_UNAPPLIED:
- has = g_delayed_settings_backend_get_has_unapplied (delayed);
- g_value_set_boolean (value, has);
- break;
-
- default:
- g_assert_not_reached ();
- }
-}
-
-static void
-g_delayed_settings_backend_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (object);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- g_assert (delayed->priv->backend == NULL);
- delayed->priv->backend = g_value_dup_object (value);
- break;
-
- default:
- g_assert_not_reached ();
- }
-}
-
+/* change notification */
static void
delayed_backend_changed (GSettingsBackend *backend,
- const gchar *name,
+ const gchar *key,
gpointer origin_tag,
gpointer user_data)
{
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (user_data);
if (origin_tag != delayed->priv)
- g_settings_backend_changed (backend, name, origin_tag);
+ g_settings_backend_changed (G_SETTINGS_BACKEND (delayed),
+ key, origin_tag);
}
static void
delayed_backend_keys_changed (GSettingsBackend *backend,
- const gchar *prefix,
+ const gchar *path,
const gchar * const *items,
gpointer origin_tag,
gpointer user_data)
@@ -217,41 +201,48 @@ delayed_backend_keys_changed (GSettingsBackend *backend,
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (user_data);
if (origin_tag != delayed->priv)
- g_settings_backend_keys_changed (backend, prefix, items, origin_tag);
+ g_settings_backend_keys_changed (G_SETTINGS_BACKEND (delayed),
+ path, items, origin_tag);
+}
+
+static void
+delayed_backend_path_changed (GSettingsBackend *backend,
+ const gchar *path,
+ gpointer origin_tag,
+ gpointer user_data)
+{
+ GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (user_data);
+
+ if (origin_tag != delayed->priv)
+ g_settings_backend_path_changed (G_SETTINGS_BACKEND (delayed),
+ path, origin_tag);
}
static void
delayed_backend_writable_changed (GSettingsBackend *backend,
- const gchar *name,
+ const gchar *key,
gpointer user_data)
{
+ GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (user_data);
+
/* XXX: maybe drop keys from the delayed-apply settings
* if they became non-writable?
*/
- g_settings_backend_writable_changed (backend, name);
+ g_settings_backend_writable_changed (G_SETTINGS_BACKEND (delayed), key);
}
static void
-g_delayed_settings_backend_constructed (GObject *object)
+delayed_backend_path_writable_changed (GSettingsBackend *backend,
+ const gchar *path,
+ gpointer user_data)
{
- GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (object);
-
- g_assert (delayed->priv->backend != NULL);
-
- delayed->priv->changed_handler_id =
- g_signal_connect (delayed->priv->backend, "changed",
- G_CALLBACK (delayed_backend_changed),
- delayed);
-
- delayed->priv->keys_changed_handler_id =
- g_signal_connect (delayed->priv->backend, "keys-changed",
- G_CALLBACK (delayed_backend_keys_changed),
- delayed);
+ GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (user_data);
- delayed->priv->writable_changed_handler_id =
- g_signal_connect (delayed->priv->backend, "writable-changed",
- G_CALLBACK (delayed_backend_writable_changed),
- delayed);
+ /* XXX: maybe drop keys from the delayed-apply settings
+ * if they became non-writable?
+ */
+ g_settings_backend_path_writable_changed (G_SETTINGS_BACKEND (delayed),
+ path);
}
static void
@@ -259,12 +250,7 @@ g_delayed_settings_backend_finalize (GObject *object)
{
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (object);
- g_signal_handler_disconnect (delayed->priv->backend,
- delayed->priv->changed_handler_id);
- g_signal_handler_disconnect (delayed->priv->backend,
- delayed->priv->keys_changed_handler_id);
- g_signal_handler_disconnect (delayed->priv->backend,
- delayed->priv->writable_changed_handler_id);
+ g_settings_backend_unwatch (delayed->priv->backend, delayed);
g_object_unref (delayed->priv->backend);
}
@@ -276,33 +262,16 @@ g_delayed_settings_backend_class_init (GDelayedSettingsBackendClass *class)
g_type_class_add_private (class, sizeof (GDelayedSettingsBackendPrivate));
+ backend_class->read = g_delayed_settings_backend_read;
backend_class->write = g_delayed_settings_backend_write;
backend_class->write_keys = g_delayed_settings_backend_write_keys;
- backend_class->read = g_delayed_settings_backend_read;
+ backend_class->reset = g_delayed_settings_backend_reset;
+ backend_class->reset_path = g_delayed_settings_backend_reset_path;
backend_class->get_writable = g_delayed_settings_backend_get_writable;
backend_class->subscribe = g_delayed_settings_backend_subscribe;
backend_class->unsubscribe = g_delayed_settings_backend_subscribe;
- object_class->get_property = g_delayed_settings_backend_get_property;
- object_class->set_property = g_delayed_settings_backend_set_property;
- object_class->constructed = g_delayed_settings_backend_constructed;
object_class->finalize = g_delayed_settings_backend_finalize;
-
- g_object_class_install_property (object_class, PROP_BACKEND,
- g_param_spec_object ("backend",
- P_("Backend"),
- P_("The actual backend"),
- G_TYPE_SETTINGS_BACKEND,
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class, PROP_HAS_UNAPPLIED,
- g_param_spec_boolean ("has-unapplied",
- P_("Has unapplied"),
- P_("TRUE if there are unapplied changes"),
- FALSE,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
}
static void
@@ -315,9 +284,23 @@ g_delayed_settings_backend_init (GDelayedSettingsBackend *delayed)
delayed->priv->delayed = g_settings_backend_create_tree ();
}
-GSettingsBackend *
-g_delayed_settings_backend_new (GSettingsBackend *backend)
+GDelayedSettingsBackend *
+g_delayed_settings_backend_new (GSettingsBackend *backend,
+ gpointer owner)
{
- return g_object_new (G_TYPE_DELAYED_SETTINGS_BACKEND,
- "backend", backend, NULL);
+ GDelayedSettingsBackend *delayed;
+
+ delayed = g_object_new (G_TYPE_DELAYED_SETTINGS_BACKEND, NULL);
+ delayed->priv->backend = g_object_ref (backend);
+ delayed->priv->owner = owner;
+
+ g_settings_backend_watch (delayed->priv->backend,
+ delayed_backend_changed,
+ delayed_backend_path_changed,
+ delayed_backend_keys_changed,
+ delayed_backend_writable_changed,
+ delayed_backend_path_writable_changed,
+ delayed);
+
+ return delayed;
}
diff --git a/gio/gdelayedsettingsbackend.h b/gio/gdelayedsettingsbackend.h
index 39b6462..50d126d 100644
--- a/gio/gdelayedsettingsbackend.h
+++ b/gio/gdelayedsettingsbackend.h
@@ -46,14 +46,12 @@ struct _GDelayedSettingsBackend
GDelayedSettingsBackendPrivate *priv;
};
-G_BEGIN_DECLS
-
GType g_delayed_settings_backend_get_type (void);
-GSettingsBackend * g_delayed_settings_backend_new (GSettingsBackend *backend);
+GDelayedSettingsBackend * g_delayed_settings_backend_new (GSettingsBackend *backend,
+ gpointer owner);
+void g_delayed_settings_backend_disown (GDelayedSettingsBackend *backend);
void g_delayed_settings_backend_revert (GDelayedSettingsBackend *delayed);
void g_delayed_settings_backend_apply (GDelayedSettingsBackend *delayed);
gboolean g_delayed_settings_backend_get_has_unapplied (GDelayedSettingsBackend *delayed);
-G_END_DECLS
-
#endif /* __G_DELAYED_SETTINGS_BACKEND_H__ */
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 676d979..6699459 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -376,36 +376,24 @@ g_settings_notify_unapplied (GSettings *settings)
* Since: 2.26
*/
void
-g_settings_set_delay_apply (GSettings *settings,
- gboolean delayed)
+g_settings_delay (GSettings *settings)
{
- delayed = !!delayed;
+ if (settings->priv->delayed)
+ return;
- if (delayed != settings->priv->delayed)
- {
- GSettingsBackend *backend;
-
- g_assert (delayed);
-
- backend = g_delayed_settings_backend_new (settings->priv->backend);
- g_settings_backend_unwatch (settings->priv->backend, settings);
- g_settings_backend_watch (backend,
- settings_backend_changed,
- settings_backend_path_changed,
- settings_backend_keys_changed,
- settings_backend_writable_changed,
- settings_backend_path_writable_changed,
- settings);
- g_object_unref (settings->priv->backend);
-
- settings->priv->backend = backend;
- settings->priv->unapplied_handler =
- g_signal_connect_swapped (backend, "notify::has-unapplied",
- G_CALLBACK (g_settings_notify_unapplied),
- settings);
-
- settings->priv->delayed = TRUE;
- }
+ settings->priv->delayed =
+ g_delayed_settings_backend_new (settings->priv->backend, settings);
+ g_settings_backend_unwatch (settings->priv->backend, settings);
+ g_object_unref (settings->priv->backend);
+
+ settings->priv->backend = G_SETTINGS_BACKEND (settings->priv->delayed);
+ g_settings_backend_watch (settings->priv->backend,
+ settings_backend_changed,
+ settings_backend_path_changed,
+ settings_backend_keys_changed,
+ settings_backend_writable_changed,
+ settings_backend_path_writable_changed,
+ settings);
}
/**
diff --git a/gio/gsettings.h b/gio/gsettings.h
index 17b53f1..0f5ee6a 100644
--- a/gio/gsettings.h
+++ b/gio/gsettings.h
@@ -100,12 +100,10 @@ void g_settings_reset_all (GSettin
gboolean g_settings_is_writable (GSettings *settings,
const gchar *name);
+void g_settings_delay (GSettings *settings);
void g_settings_apply (GSettings *settings);
void g_settings_revert (GSettings *settings);
-gboolean g_settings_get_delay_apply (GSettings *settings);
gboolean g_settings_get_has_unapplied (GSettings *settings);
-void g_settings_set_delay_apply (GSettings *settings,
- gboolean delay);
typedef GVariant * (*GSettingsBindSetMapping) (const GValue *value,
const GVariantType *expected_type,
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index 981e0d4..beddc26 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -322,10 +322,7 @@ test_delay_apply (void)
g_signal_connect (settings2, "changed",
G_CALLBACK (changed_cb2), &changed_cb_called2);
- g_settings_set_delay_apply (settings, TRUE);
-
- g_assert (g_settings_get_delay_apply (settings));
- g_assert (!g_settings_get_delay_apply (settings2));
+ g_settings_delay (settings);
g_settings_set (settings, "greeting", "s", "greetings from test_delay_apply");
@@ -379,7 +376,7 @@ test_delay_revert (void)
g_settings_set (settings2, "greeting", "s", "top o' the morning");
- g_settings_set_delay_apply (settings, TRUE);
+ g_settings_delay (settings);
g_settings_set (settings, "greeting", "s", "greetings from test_delay_revert");
@@ -449,7 +446,7 @@ test_atomic (void)
g_signal_connect (settings2, "keys-changed",
G_CALLBACK (keys_changed_cb), NULL);
- g_settings_set_delay_apply (settings, TRUE);
+ g_settings_delay (settings);
g_settings_set (settings, "greeting", "s", "greetings from test_atomic");
g_settings_set (settings, "farewell", "s", "atomic bye-bye");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]