Implement ibus_bus_get_config function.

This commit is contained in:
Huang Peng 2009-03-09 17:21:45 +08:00
Родитель a1ac8682c8
Коммит 21b7963087
7 изменённых файлов: 200 добавлений и 53 удалений

Просмотреть файл

@ -828,6 +828,16 @@ _connection_ibus_message_cb (BusConnection *connection,
ibus_message_get_error_message (message));
break;
#endif
#if 0
case DBUS_MESSAGE_TYPE_SIGNAL:
g_debug ("From :%s to %s, Signal: %s @ %s",
ibus_message_get_sender (message),
ibus_message_get_destination (message),
ibus_message_get_member (message),
ibus_message_get_path (message)
);
break;
#endif
#if 0
case DBUS_MESSAGE_TYPE_METHOD_CALL:
g_debug("From %s to %s, Method %s on %s",
@ -1068,10 +1078,9 @@ bus_dbus_impl_dispatch_message_by_rule (BusDBusImpl *dbus,
#endif
for (link = dbus->rules; link != NULL; link = link->next) {
recipients = bus_match_rule_get_recipients (BUS_MATCH_RULE (link->data),
message);
if (recipients != NULL)
break;
GList *list = bus_match_rule_get_recipients (BUS_MATCH_RULE (link->data),
message);
recipients = g_list_concat (recipients, list);
}
for (link = recipients; link != NULL; link = link->next) {

Просмотреть файл

@ -270,6 +270,8 @@ bus_match_rule_new (const gchar *text)
{
g_assert (text != NULL);
g_debug ("new rule=%s", text);
Token *tokens, *p;
BusMatchRule *rule;
@ -499,6 +501,7 @@ bus_match_rule_match (BusMatchRule *rule,
ibus_message_iter_next (&iter);
}
}
return TRUE;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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) {
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_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);
}
g_signal_connect (priv->connection,
"ibus-signal",
(GCallback) _connection_ibus_signal_cb,
proxy);
g_signal_connect (priv->connection,
"destroy",
(GCallback) _connection_destroy_cb,
proxy);
if (priv->connection == NULL) {
g_object_unref (proxy);
return NULL;
}
if (priv->name != NULL) {
IBusError *error;
gchar *rule;
if (ibus_proxy_get_unique_name (proxy) == NULL) {
g_object_unref (proxy);
return NULL;
}
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_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,7 @@ 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,
@ -320,10 +354,33 @@ ibus_proxy_destroy (IBusProxy *proxy)
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,
"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);
}
}
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)
{

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;
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);
bus = ibus_bus_new ();
config = ibus_bus_get_config (bus);
g_signal_connect (config,
"value-changed",
G_CALLBACK (_value_changed_cb),
NULL);
g_main_loop_run (g_main_loop_new (NULL, FALSE));
return 0;
}