From db3538af64127d9903ae54ea49c63d5887b8f30f Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Thu, 1 Sep 2011 11:19:41 +0900 Subject: [PATCH] Send DestroyContext when EekboardClient#dispose. --- eekboard/eekboard-client.c | 48 ++++++++++++++++++++++++++++---------- src/client.c | 4 ---- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/eekboard/eekboard-client.c b/eekboard/eekboard-client.c index 1ecb02c6..e2b5600f 100644 --- a/eekboard/eekboard-client.c +++ b/eekboard/eekboard-client.c @@ -46,6 +46,10 @@ struct _EekboardClientPrivate GHashTable *context_hash; }; +static void send_destroy_context (EekboardClient *client, + EekboardContext *context, + GCancellable *cancellable); + static void eekboard_client_real_destroyed (EekboardClient *self) { @@ -58,9 +62,18 @@ eekboard_client_real_destroyed (EekboardClient *self) static void eekboard_client_dispose (GObject *object) { - EekboardClientPrivate *priv = EEKBOARD_CLIENT_GET_PRIVATE(object); + EekboardClient *client = EEKBOARD_CLIENT(object); + EekboardClientPrivate *priv = EEKBOARD_CLIENT_GET_PRIVATE(client); if (priv->context_hash) { + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init (&iter, priv->context_hash); + while (g_hash_table_iter_next (&iter, &key, &value)) { + send_destroy_context (client, (EekboardContext *)value, NULL); + g_hash_table_iter_remove (&iter); + } g_hash_table_destroy (priv->context_hash); priv->context_hash = NULL; } @@ -309,6 +322,25 @@ eekboard_client_pop_context (EekboardClient *client, NULL); } +static void +send_destroy_context (EekboardClient *client, + EekboardContext *context, + GCancellable *cancellable) +{ + const gchar *object_path; + + object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context)); + + g_dbus_proxy_call (G_DBUS_PROXY(client), + "DestroyContext", + g_variant_new ("(s)", object_path), + G_DBUS_CALL_FLAGS_NONE, + -1, + cancellable, + eekboard_async_ready_callback, + NULL); +} + /** * eekboard_client_destroy_context: * @eekboard: an #EekboardClient @@ -328,16 +360,8 @@ eekboard_client_destroy_context (EekboardClient *client, g_return_if_fail (EEKBOARD_IS_CLIENT(client)); g_return_if_fail (EEKBOARD_IS_CONTEXT(context)); - priv = EEKBOARD_CLIENT_GET_PRIVATE(client); - object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context)); - g_hash_table_remove (priv->context_hash, object_path); + send_destroy_context (client, context, cancellable); - g_dbus_proxy_call (G_DBUS_PROXY(client), - "DestroyContext", - g_variant_new ("(s)", object_path), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - eekboard_async_ready_callback, - NULL); + priv = EEKBOARD_CLIENT_GET_PRIVATE(client); + g_hash_table_remove (priv->context_hash, object_path); } diff --git a/src/client.c b/src/client.c index 13f13116..ba409054 100644 --- a/src/client.c +++ b/src/client.c @@ -219,10 +219,6 @@ client_dispose (GObject *object) #endif /* HAVE_XTEST */ if (client->context) { - if (client->eekboard) { - eekboard_client_pop_context (client->eekboard, NULL); - } - g_object_unref (client->context); client->context = NULL; }