From 21b79630873c79ced591cf5e909660cf4c1bda69 Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Mon, 9 Mar 2009 17:21:45 +0800 Subject: Implement ibus_bus_get_config function. --- src/ibusbus.c | 42 ++++++++++++++- src/ibusbus.h | 2 + src/ibusproxy.c | 158 ++++++++++++++++++++++++++++++++++++++++++------------- src/ibusproxy.h | 1 + src/test-proxy.c | 24 ++++++--- 5 files changed, 181 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/ibusbus.c b/src/ibusbus.c index 52631e8..4115689 100644 --- a/src/ibusbus.c +++ b/src/ibusbus.c @@ -23,6 +23,7 @@ #include "ibusinternal.h" #include "ibusshare.h" #include "ibusconnection.h" +#include "ibusconfig.h" #define IBUS_BUS_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_BUS, IBusBusPrivate)) @@ -40,6 +41,7 @@ struct _IBusBusPrivate { GFileMonitor *monitor; IBusConnection *connection; gboolean watch_dbus_signal; + IBusConfig *config; }; typedef struct _IBusBusPrivate IBusBusPrivate; @@ -210,6 +212,7 @@ ibus_bus_init (IBusBus *bus) IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); + priv->config = NULL; priv->connection = NULL; priv->watch_dbus_signal = FALSE; @@ -239,8 +242,13 @@ ibus_bus_destroy (IBusObject *object) priv->monitor = NULL; } + if (priv->config) { + ibus_object_destroy ((IBusObject *) priv->config); + priv->config = NULL; + } + if (priv->connection) { - ibus_object_destroy (IBUS_OBJECT (priv->connection)); + ibus_object_destroy ((IBusObject *) priv->connection); priv->connection = NULL; } @@ -613,7 +621,7 @@ ibus_bus_get_name_owner (IBusBus *bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, - "RemoveMatch", + "GetNameOwner", G_TYPE_STRING, &name, G_TYPE_INVALID, G_TYPE_STRING, &owner, @@ -729,3 +737,33 @@ ibus_bus_list_active_engines (IBusBus *bus) { return NULL; } + +static void +_config_destroy_cb (IBusConfig *config, + IBusBus *bus) +{ + IBusBusPrivate *priv; + priv = IBUS_BUS_GET_PRIVATE (bus); + + g_assert (priv->config == config); + + g_object_unref (config); + priv->config = NULL; +} + +IBusConfig * +ibus_bus_get_config (IBusBus *bus) +{ + g_assert (IBUS_IS_BUS (bus)); + IBusBusPrivate *priv; + priv = IBUS_BUS_GET_PRIVATE (bus); + + if (priv->config == NULL && priv->connection) { + priv->config = ibus_config_new (priv->connection); + if (priv->config) { + g_signal_connect (priv->config, "destroy", G_CALLBACK (_config_destroy_cb), bus); + } + } + + return priv->config; +} diff --git a/src/ibusbus.h b/src/ibusbus.h index be1fba8..e02c193 100644 --- a/src/ibusbus.h +++ b/src/ibusbus.h @@ -92,6 +92,8 @@ gboolean ibus_bus_register_component(IBusBus *bus, GList *ibus_bus_list_engines (IBusBus *bus); GList *ibus_bus_list_active_engines (IBusBus *bus); +/* declare config apis */ +IBusConfig *ibus_bus_get_config (IBusBus *bus); G_END_DECLS #endif diff --git a/src/ibusproxy.c b/src/ibusproxy.c index 5ef3b40..9abf8f6 100644 --- a/src/ibusproxy.c +++ b/src/ibusproxy.c @@ -43,6 +43,7 @@ enum { /* IBusProxyPriv */ struct _IBusProxyPrivate { gchar *name; + gchar *unique_name; gchar *path; gchar *interface; IBusConnection *connection; @@ -187,6 +188,12 @@ _connection_ibus_signal_cb (IBusConnection *connection, IBusMessage *message, IBusProxy *proxy) { + IBusProxyPrivate *priv; + priv = IBUS_PROXY_GET_PRIVATE (proxy); + + if (g_strcmp0 (ibus_message_get_path (message), priv->path) != 0) + return FALSE; + if (ibus_proxy_handle_signal (proxy, message)) { g_signal_stop_emission_by_name (connection, "ibus-signal"); return TRUE; @@ -224,45 +231,71 @@ ibus_proxy_constructor (GType type, proxy = IBUS_PROXY (obj); priv = IBUS_PROXY_GET_PRIVATE (proxy); - if (priv->connection != NULL) { - if (priv->name != NULL) { + if (priv->connection == NULL) { + g_object_unref (proxy); + return NULL; + } - IBusError *error; - gchar *rule; + if (priv->name != NULL) { + IBusError *error; + gchar *rule; - rule = g_strdup_printf ("type='signal'," - "sender='" DBUS_SERVICE_DBUS "'," - "path='" DBUS_PATH_DBUS "'," - "interface='" DBUS_INTERFACE_DBUS "'," - "member='NameOwnerChanged'," - "arg0='%s'", - priv->name); + if (ibus_proxy_get_unique_name (proxy) == NULL) { + g_object_unref (proxy); + return NULL; + } - if (!ibus_connection_call (priv->connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "AddMatch", - &error, - G_TYPE_STRING, &rule, - G_TYPE_INVALID, - G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } - g_free (rule); + rule = g_strdup_printf ("type='signal'," + "sender='" DBUS_SERVICE_DBUS "'," + "path='" DBUS_PATH_DBUS "'," + "interface='" DBUS_INTERFACE_DBUS "'," + "member='NameOwnerChanged'," + "arg0='%s'", + priv->unique_name); + + if (!ibus_connection_call (priv->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "AddMatch", + &error, + G_TYPE_STRING, &rule, + G_TYPE_INVALID, + G_TYPE_INVALID)) { + g_warning ("%s: %s", error->name, error->message); + ibus_error_free (error); + } + g_free (rule); + + rule = g_strdup_printf ("type='signal'," + "sender='%s'," + "path='%s'", + priv->unique_name, + priv->path); + + if (!ibus_connection_call (priv->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "AddMatch", + &error, + G_TYPE_STRING, &rule, + G_TYPE_INVALID, + G_TYPE_INVALID)) { + g_warning ("%s: %s", error->name, error->message); + ibus_error_free (error); } - g_signal_connect (priv->connection, - "ibus-signal", - (GCallback) _connection_ibus_signal_cb, - proxy); - - g_signal_connect (priv->connection, - "destroy", - (GCallback) _connection_destroy_cb, - proxy); + g_free (rule); } - + g_signal_connect (priv->connection, + "ibus-signal", + (GCallback) _connection_ibus_signal_cb, + proxy); + + g_signal_connect (priv->connection, + "destroy", + (GCallback) _connection_destroy_cb, + proxy); return obj; } @@ -273,6 +306,7 @@ ibus_proxy_init (IBusProxy *proxy) priv = IBUS_PROXY_GET_PRIVATE (proxy); priv->name = NULL; + priv->unique_name = NULL; priv->path = NULL; priv->interface = NULL; priv->connection = NULL; @@ -304,7 +338,28 @@ ibus_proxy_destroy (IBusProxy *proxy) "interface='" DBUS_INTERFACE_DBUS "'," "member='NameOwnerChanged'," "arg0='%s'", - priv->name); + priv->unique_name); + + if (!ibus_connection_call (priv->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "RemoveMatch", + &error, + G_TYPE_STRING, &rule, + G_TYPE_INVALID, + G_TYPE_INVALID)) { + + g_warning ("%s: %s", error->name, error->message); + ibus_error_free (error); + } + g_free (rule); + + rule = g_strdup_printf ("type='signal'," + "sender='%s'," + "path='%s'", + priv->unique_name, + priv->path); if (!ibus_connection_call (priv->connection, DBUS_SERVICE_DBUS, @@ -320,10 +375,12 @@ ibus_proxy_destroy (IBusProxy *proxy) ibus_error_free (error); } g_free (rule); + } } g_free (priv->name); + g_free (priv->unique_name); g_free (priv->path); g_free (priv->interface); @@ -421,7 +478,7 @@ ibus_proxy_handle_signal (IBusProxy *proxy, ibus_error_free (error); } - if (g_strcmp0 (priv->name, old_name) == 0) { + if (g_strcmp0 (priv->unique_name, old_name) == 0) { ibus_object_destroy (IBUS_OBJECT (proxy)); return FALSE; } @@ -451,6 +508,35 @@ ibus_proxy_get_name (IBusProxy *proxy) return priv->name; } +const gchar * +ibus_proxy_get_unique_name (IBusProxy *proxy) +{ + + IBusProxyPrivate *priv; + priv = IBUS_PROXY_GET_PRIVATE (proxy); + + if (priv->unique_name == NULL && priv->connection != NULL) { + IBusError *error; + gchar *owner; + if (!ibus_connection_call (priv->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "GetNameOwner", + &error, + G_TYPE_STRING, &(priv->name), + G_TYPE_INVALID, + G_TYPE_STRING, &owner, + G_TYPE_INVALID)) { + g_warning ("%s: %s", error->name, error->message); + ibus_error_free (error); + } + priv->unique_name = g_strdup (owner); + } + + return priv->unique_name; +} + const gchar * ibus_proxy_get_path (IBusProxy *proxy) { diff --git a/src/ibusproxy.h b/src/ibusproxy.h index 0cc22d4..ce85b4d 100644 --- a/src/ibusproxy.h +++ b/src/ibusproxy.h @@ -98,6 +98,7 @@ IBusMessage *ibus_proxy_send_with_reply_and_block gboolean ibus_proxy_handle_signal (IBusProxy *proxy, IBusMessage *message); const gchar *ibus_proxy_get_name (IBusProxy *proxy); +const gchar *ibus_proxy_get_unique_name (IBusProxy *proxy); const gchar *ibus_proxy_get_path (IBusProxy *proxy); const gchar *ibus_proxy_get_interface (IBusProxy *proxy); IBusConnection *ibus_proxy_get_connection (IBusProxy *proxy); diff --git a/src/test-proxy.c b/src/test-proxy.c index 31866f1..aedd732 100644 --- a/src/test-proxy.c +++ b/src/test-proxy.c @@ -1,18 +1,26 @@ #include "ibus.h" +static +_value_changed_cb (IBusConfig *config, gchar *section, gchar *name, GValue *value, gpointer data) +{ + g_debug ("value-changed %s %s", section, name); +} + int main() { g_type_init (); - IBusConnection *connection; - IBusProxy *proxy; + IBusBus *bus; + IBusConfig *config; + + bus = ibus_bus_new (); + config = ibus_bus_get_config (bus); - connection = ibus_connection_new (); - proxy = ibus_proxy_new ("a", "/a", connection); - GValue value = {0}; - g_value_init (&value, G_TYPE_STRING); - g_value_set_static_string (&value, "aaa"); - g_object_set_property (G_OBJECT (proxy), "name", &value); + g_signal_connect (config, + "value-changed", + G_CALLBACK (_value_changed_cb), + NULL); + g_main_loop_run (g_main_loop_new (NULL, FALSE)); return 0; } -- cgit From 0dc9376baaf67e8fcb363b1c9623bd634e35ccff Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Wed, 11 Mar 2009 14:38:14 +0800 Subject: Fix problems during making distcheck --- src/Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index ba868e0..9b3eafe 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -73,7 +73,6 @@ ibus_h_sources = \ ibusconfigprivate.h \ keyname-table.h \ $(ibus_public_h_sources) \ - $(ibus_built_public_h_sources) \ $(NULL) ibus_c_sources = \ ibusshare.c \ @@ -103,19 +102,20 @@ ibus_c_sources = \ ibusenginedesc.c \ ibusobservedpath.c \ ibuscomponent.c \ - $(ibus_built_c_sources) \ $(NULL) - ibusincludedir = $(includedir)/ibus-1.0 ibusinclude_HEADERS = \ $(ibus_public_h_sources) \ $(ibus_built_public_h_sources) \ $(NULL) - libibus_la_SOURCES = \ $(ibus_h_sources) \ $(ibus_c_sources) \ $(NULL) +nodist_libibus_la_SOURCES = \ + $(ibus_built_h_sources) \ + $(ibus_built_c_sources) \ + $(NULL) libibus_la_CFLAGS = \ @X11_CFLAGS@ \ @GLIB2_CFLAGS@ \ -- cgit From 6af7e9f2f1ff18e4a6334d15f14c27e3edf2111c Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Wed, 11 Mar 2009 15:51:34 +0800 Subject: Implement ibus_engine_forward_event_key function. --- src/ibusengine.c | 4 +--- src/ibusengine.h | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/ibusengine.c b/src/ibusengine.c index d924e25..e664454 100644 --- a/src/ibusengine.c +++ b/src/ibusengine.c @@ -942,13 +942,11 @@ void ibus_engine_hide_lookup_table (IBusEngine *engine) void ibus_engine_forward_key_event (IBusEngine *engine, guint keyval, - gboolean is_press, guint state) { _send_signal (engine, - "HideLookupTable", + "ForwardKeyEvent", G_TYPE_UINT, &keyval, - G_TYPE_BOOLEAN, &is_press, G_TYPE_UINT, &state, G_TYPE_INVALID); } diff --git a/src/ibusengine.h b/src/ibusengine.h index 1a35c06..5a86bf0 100644 --- a/src/ibusengine.h +++ b/src/ibusengine.h @@ -137,7 +137,6 @@ void ibus_engine_hide_lookup_table void ibus_engine_forward_key_event (IBusEngine *engine, guint keyval, - gboolean is_press, guint state); void ibus_engine_register_properties -- cgit From 9f2ca25b5638cc1e3f10a2671472dbd72e45e479 Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Wed, 11 Mar 2009 15:54:39 +0800 Subject: Remove is_press from ForwardKeyEvent signal. --- src/ibusinputcontext.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/ibusinputcontext.c b/src/ibusinputcontext.c index 94de55a..95754cf 100644 --- a/src/ibusinputcontext.c +++ b/src/ibusinputcontext.c @@ -426,14 +426,12 @@ ibus_input_context_ibus_signal (IBusProxy *proxy, IBUS_INTERFACE_INPUT_CONTEXT, "ForwardKeyEvent")) { guint32 keyval; - gboolean is_press; guint32 state; gboolean retval; retval = ibus_message_get_args (message, &error, G_TYPE_UINT, &keyval, - G_TYPE_BOOLEAN, &is_press, G_TYPE_UINT, &state, G_TYPE_INVALID); -- cgit