summaryrefslogtreecommitdiff
path: root/wrappers
diff options
context:
space:
mode:
authorHavoc Pennington <hp@pobox.com>2000-06-01 23:38:46 +0000
committerHavoc Pennington <hp@src.gnome.org>2000-06-01 23:38:46 +0000
commit56a8ba3b013d0184414e44898cf5d3e2e72ebca9 (patch)
tree007b1edf701cf2cda7c97703653390e8ee1c7668 /wrappers
parente2692320e42b216e661b20dde8478afc1cf3f5c1 (diff)
downloadgconf-56a8ba3b013d0184414e44898cf5d3e2e72ebca9.tar.gz
If there's an existing engine for a given context, return that engine
2000-06-01 Havoc Pennington <hp@pobox.com> * gconf/gconf.c (gconf_engine_new): If there's an existing engine for a given context, return that engine instead of creating a new one. (gconf_engine_new_from_address): ditto * wrappers/gtk/gconf-client.c (gconf_client_finalize): remove client from client registration table (gconf_client_new): register newly-created client in hash from engines to clients; return an existing client if there's already a client for the default engine (gconf_client_new_with_engine): register newly-created client, and try to return existing client.
Diffstat (limited to 'wrappers')
-rw-r--r--wrappers/gtk/gconf-client.c76
1 files changed, 68 insertions, 8 deletions
diff --git a/wrappers/gtk/gconf-client.c b/wrappers/gtk/gconf-client.c
index faa633c9..0bdbc642 100644
--- a/wrappers/gtk/gconf-client.c
+++ b/wrappers/gtk/gconf-client.c
@@ -113,6 +113,10 @@ enum {
LAST_SIGNAL
};
+static void register_client (GConfClient *client);
+static GConfClient *lookup_client (GConfEngine *engine);
+static void unregister_client (GConfClient *client);
+
static void gconf_client_class_init (GConfClientClass *klass);
static void gconf_client_init (GConfClient *client);
static void gconf_client_real_unreturned_error (GConfClient* client, GConfError* error);
@@ -262,6 +266,8 @@ gconf_client_finalize (GtkObject* object)
g_hash_table_destroy(client->cache_hash);
client->cache_hash = NULL;
+
+ unregister_client (client);
if (client->engine != NULL)
{
@@ -411,12 +417,26 @@ GConfClient*
gconf_client_new (void)
{
GConfClient *client;
-
- g_return_val_if_fail(gconf_is_initialized(), NULL);
+ GConfEngine *engine;
- client = gtk_type_new (gconf_client_get_type ());
+ g_return_val_if_fail(gconf_is_initialized(), NULL);
- client->engine = gconf_engine_new();
+ engine = gconf_engine_new ();
+
+ client = lookup_client (engine);
+ if (client)
+ {
+ g_assert (client->engine == engine);
+ gtk_object_ref (GTK_OBJECT (client));
+ gconf_engine_unref (engine);
+ return client;
+ }
+ else
+ {
+ client = gtk_type_new (gconf_client_get_type ());
+ client->engine = engine;
+ register_client (client);
+ }
return client;
}
@@ -427,12 +447,24 @@ gconf_client_new_with_engine (GConfEngine* engine)
GConfClient *client;
g_return_val_if_fail(gconf_is_initialized(), NULL);
-
- client = gtk_type_new (gconf_client_get_type ());
- client->engine = engine;
+ client = lookup_client (engine);
+ if (client)
+ {
+ g_assert (client->engine == engine);
+ gtk_object_ref (GTK_OBJECT (client));
+ return client;
+ }
+ else
+ {
+ client = gtk_type_new (gconf_client_get_type ());
+
+ client->engine = engine;
- gconf_engine_ref(client->engine);
+ gconf_engine_ref(client->engine);
+
+ register_client (client);
+ }
return client;
}
@@ -1888,3 +1920,31 @@ gconf_client_create_change_set_from_current (GConfClient* client,
return retval;
}
+
+static GHashTable * clients = NULL;
+
+static void
+register_client (GConfClient *client)
+{
+ if (clients == NULL)
+ clients = g_hash_table_new (NULL, NULL);
+
+ g_hash_table_insert (clients, client->engine, client);
+}
+
+static GConfClient *
+lookup_client (GConfEngine *engine)
+{
+ if (clients == NULL)
+ return NULL;
+ else
+ return g_hash_table_lookup (clients, engine);
+}
+
+static void
+unregister_client (GConfClient *client)
+{
+ g_return_if_fail (clients != NULL);
+
+ g_hash_table_remove (clients, client->engine);
+}