コード例 #1
0
ファイル: ibusbus.c プロジェクト: hychen/ibus
gboolean
ibus_bus_get_use_global_engine (IBusBus *bus)
{
    g_assert (IBUS_IS_BUS (bus));

    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    gboolean use_global_engine = FALSE;

    reply = ibus_bus_call_with_reply (bus,
                                      IBUS_SERVICE_IBUS,
                                      IBUS_PATH_IBUS,
                                      IBUS_INTERFACE_IBUS,
                                      "GetUseGlobalEngine",
                                      G_TYPE_INVALID);
    if (reply) {
        if (!ibus_message_get_args (reply, &error, G_TYPE_BOOLEAN,
                                    &use_global_engine, G_TYPE_INVALID)) {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return use_global_engine;
}
コード例 #2
0
ファイル: ibusbus.c プロジェクト: hychen/ibus
gboolean
ibus_bus_name_has_owner (IBusBus        *bus,
                         const gchar    *name)
{
    g_assert (IBUS_IS_BUS (bus));

    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    gboolean retval = FALSE;

    reply = ibus_bus_call_with_reply (bus,
                                      DBUS_SERVICE_DBUS,
                                      DBUS_PATH_DBUS,
                                      DBUS_INTERFACE_DBUS,
                                      "NameHasOwner",
                                      G_TYPE_STRING, &name,
                                      G_TYPE_INVALID);

    if (reply) {
        if (!ibus_message_get_args (reply, &error, G_TYPE_BOOLEAN, &retval,
                                    G_TYPE_INVALID)) {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return retval;
}
コード例 #3
0
ファイル: ibusbus.c プロジェクト: hychen/ibus
gchar *
ibus_bus_get_name_owner (IBusBus        *bus,
                         const gchar    *name)
{
    g_assert (IBUS_IS_BUS (bus));

    gchar *owner = NULL;
    IBusMessage *reply = NULL;
    IBusError *error = NULL;

    reply = ibus_bus_call_with_reply (bus,
                                      DBUS_SERVICE_DBUS,
                                      DBUS_PATH_DBUS,
                                      DBUS_INTERFACE_DBUS,
                                      "GetNameOwner",
                                      G_TYPE_STRING, &name,
                                      G_TYPE_INVALID);

    if (reply) {
        if (ibus_message_get_args (reply, &error, G_TYPE_STRING, &owner,
                                   G_TYPE_INVALID)) {
            owner = g_strdup (owner);
        } else {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return owner;
}
コード例 #4
0
ファイル: dbusimpl.c プロジェクト: iwaim/ibus
static IBusMessage *
_dbus_release_name (BusDBusImpl     *dbus,
                    IBusMessage     *message,
                    BusConnection   *connection)
{
    IBusMessage *reply_message;
    IBusError *error;
    gchar *name;
    guint retval;

    if (!ibus_message_get_args (message,
                                &error,
                                G_TYPE_STRING, &name,
                                G_TYPE_INVALID)) {
        reply_message = ibus_message_new_error (message,
                                                error->name,
                                                error->message);
        ibus_error_free (error);
        return reply_message;
    }

    reply_message = ibus_message_new_method_return (message);
    if (bus_connection_remove_name (connection, name)) {
        retval = 1;
    }
    else {
        retval = 2;
    }

    ibus_message_append_args (message,
                              G_TYPE_UINT, &retval,
                              G_TYPE_INVALID);

    return reply_message;
}
コード例 #5
0
ファイル: ibusbus.c プロジェクト: hychen/ibus
guint
ibus_bus_release_name (IBusBus      *bus,
                       const gchar  *name)
{
    g_assert (IBUS_IS_BUS (bus));

    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    guint retval = 0;

    reply = ibus_bus_call_with_reply (bus,
                                      DBUS_SERVICE_DBUS,
                                      DBUS_PATH_DBUS,
                                      DBUS_INTERFACE_DBUS,
                                      "ReleaseName",
                                      G_TYPE_STRING, &name,
                                      G_TYPE_INVALID);

    if (reply) {
        if (!ibus_message_get_args (reply, &error, G_TYPE_UINT, &retval,
                                    G_TYPE_INVALID)) {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return retval;
}
コード例 #6
0
ファイル: ibusbus.c プロジェクト: hychen/ibus
IBusEngineDesc *
ibus_bus_get_global_engine (IBusBus *bus)
{
    g_assert (IBUS_IS_BUS (bus));

    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    IBusEngineDesc *global_engine = NULL;

    reply = ibus_bus_call_with_reply (bus,
                                      IBUS_SERVICE_IBUS,
                                      IBUS_PATH_IBUS,
                                      IBUS_INTERFACE_IBUS,
                                      "GetGlobalEngine",
                                      G_TYPE_INVALID);
    if (reply) {
        if (!ibus_message_get_args (reply, &error, IBUS_TYPE_ENGINE_DESC,
                                    &global_engine, G_TYPE_INVALID)) {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return global_engine;
}
コード例 #7
0
ファイル: ibusbus.c プロジェクト: hychen/ibus
gchar *
ibus_bus_current_input_context(IBusBus      *bus)
{
    g_assert (IBUS_IS_BUS (bus));
    g_return_val_if_fail (ibus_bus_is_connected (bus), NULL);

    gchar *path = NULL;
    IBusMessage *reply = NULL;
    IBusError *error = NULL;

    reply = ibus_bus_call_with_reply (bus,
                                      IBUS_SERVICE_IBUS,
                                      IBUS_PATH_IBUS,
                                      IBUS_INTERFACE_IBUS,
                                      "CurrentInputContext",
                                      G_TYPE_INVALID);

    if (reply) {
        if (ibus_message_get_args (reply, &error,
                                   IBUS_TYPE_OBJECT_PATH, &path,
                                   G_TYPE_INVALID)) {
            path = g_strdup (path);
        } else {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return path;
}
コード例 #8
0
ファイル: ibusbus.c プロジェクト: BBIO/ibus
IBusInputContext *
ibus_bus_create_input_context (IBusBus      *bus,
                               const gchar  *client_name)
{
    g_assert (IBUS_IS_BUS (bus));
    g_assert (client_name != NULL);

    g_return_val_if_fail (ibus_bus_is_connected (bus), NULL);

    gchar *path;
    DBusMessage *call = NULL;
    DBusMessage *reply = NULL;
    IBusError *error;
    IBusInputContext *context = NULL;
    IBusBusPrivate *priv;
    priv = IBUS_BUS_GET_PRIVATE (bus);

    call = ibus_message_new_method_call (IBUS_SERVICE_IBUS,
                                         IBUS_PATH_IBUS,
                                         IBUS_INTERFACE_IBUS,
                                         "CreateInputContext");
    ibus_message_append_args (call,
                              G_TYPE_STRING, &client_name,
                              G_TYPE_INVALID);

    reply = ibus_connection_send_with_reply_and_block (priv->connection,
                                                       call,
                                                       -1,
                                                       &error);
    ibus_message_unref (call);

    if (reply == NULL) {
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return NULL;
    }

    if ((error = ibus_error_new_from_message (reply)) != NULL) {
        g_warning ("%s: %s", error->name, error->message);
        ibus_message_unref (reply);
        ibus_error_free (error);
        return NULL;
    }

    if (!ibus_message_get_args (reply,
                                &error,
                                IBUS_TYPE_OBJECT_PATH, &path,
                                G_TYPE_INVALID)) {
        g_warning ("%s: %s", error->name, error->message);
        ibus_message_unref (reply);
        ibus_error_free (error);

        return NULL;
    }

    context = ibus_input_context_new (path, priv->connection);
    ibus_message_unref (reply);

    return context;
}
コード例 #9
0
ファイル: ibusinputcontext.c プロジェクト: BBIO/ibus
IBusEngineDesc *
ibus_input_context_get_engine (IBusInputContext *context)
{
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
    IBusMessage *reply_message;
    IBusError *error = NULL;
    IBusSerializable *object = NULL;

    reply_message = ibus_proxy_call_with_reply_and_block ((IBusProxy *) context,
                                                          "GetEngine",
                                                          -1,
                                                          &error,
                                                          G_TYPE_INVALID);
    if (!reply_message) {
        g_debug ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return NULL;
    }

    if (!ibus_message_get_args (reply_message,
                                &error,
                                IBUS_TYPE_ENGINE_DESC, &object,
                                G_TYPE_INVALID)) {
        g_debug ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        ibus_message_unref (reply_message);
        return NULL;
    }
    ibus_message_unref (reply_message);

    return IBUS_ENGINE_DESC (object);
}
コード例 #10
0
ファイル: ibusinputcontext.c プロジェクト: BBIO/ibus
gboolean
ibus_input_context_is_enabled (IBusInputContext *context)
{
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
    gboolean retval = FALSE;

    IBusMessage *reply_message;
    IBusError *error = NULL;

    reply_message = ibus_proxy_call_with_reply_and_block ((IBusProxy *) context,
                                                          "IsEnabled",
                                                          -1,
                                                          &error,
                                                          G_TYPE_INVALID);
    if (!reply_message) {
        g_debug ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return FALSE;
    }

    if (!ibus_message_get_args (reply_message,
                                &error,
                                G_TYPE_BOOLEAN, &retval,
                                G_TYPE_INVALID)) {
        g_debug ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        retval = FALSE;
    }
    ibus_message_unref (reply_message);

    return retval;
}
コード例 #11
0
ファイル: dbusimpl.c プロジェクト: iwaim/ibus
static IBusMessage *
_dbus_request_name (BusDBusImpl     *dbus,
                    IBusMessage     *message,
                    BusConnection   *connection)
{
    IBusMessage *reply_message;
    IBusError *error;
    gchar *name;
    guint flags;
    guint retval;

    if (!ibus_message_get_args (message,
                                &error,
                                G_TYPE_STRING, &name,
                                G_TYPE_UINT, &flags,
                                G_TYPE_INVALID)) {
        reply_message = ibus_message_new_error (message,
                                                error->name,
                                                error->message);
        ibus_error_free (error);
        return reply_message;
    }

    if (g_hash_table_lookup (dbus->names, name) != NULL) {
        reply_message = ibus_message_new_error_printf (message,
                                                       DBUS_ERROR_FAILED,
                                                       "Name %s has owner",
                                                       name);
        return reply_message;
    }

    retval = 1;
    g_hash_table_insert (dbus->names,
                         (gpointer )bus_connection_add_name (connection, name),
                         connection);
    reply_message = ibus_message_new_method_return (message);
    ibus_message_append_args (reply_message,
                              G_TYPE_UINT, &retval,
                              G_TYPE_INVALID);

    ibus_connection_send ((IBusConnection *) connection, reply_message);
    ibus_message_unref (reply_message);
    ibus_connection_flush ((IBusConnection *) connection);

    g_signal_emit (dbus,
                   dbus_signals[NAME_OWNER_CHANGED],
                   0,
                   name,
                   "",
                   bus_connection_get_unique_name (connection));

    return NULL;
}
コード例 #12
0
ファイル: ibusmessage.c プロジェクト: definite/ibus
const gchar *
ibus_message_get_error_message (IBusMessage *message)
{
    gchar *error_message;
    gboolean retval;

    retval = ibus_message_get_args (message, NULL, G_TYPE_STRING, &error_message, G_TYPE_INVALID);

    if (retval)
        return error_message;
    return NULL;
}
コード例 #13
0
ファイル: dbusimpl.c プロジェクト: iwaim/ibus
static IBusMessage *
_dbus_add_match (BusDBusImpl    *dbus,
                 IBusMessage    *message,
                 BusConnection  *connection)
{
    IBusMessage *reply_message;
    IBusError *error;
    gboolean retval;
    gchar *rule_text;
    BusMatchRule *rule;
    GList *link;

    retval = ibus_message_get_args (message,
                                    &error,
                                    G_TYPE_STRING, &rule_text,
                                    G_TYPE_INVALID);

    if (!retval) {
        reply_message = ibus_message_new_error (message,
                                                error->name,
                                                error->message);
        ibus_error_free (error);
        return reply_message;
    }

    rule = bus_match_rule_new (rule_text);

    if (rule == NULL) {
         reply_message = ibus_message_new_error_printf (message,
                                                        DBUS_ERROR_MATCH_RULE_INVALID,
                                                        "Parse rule [%s] failed",
                                                        rule_text);
        return reply_message;
    }

    for (link = dbus->rules; link != NULL; link = link->next) {
        if (bus_match_rule_is_equal (rule, BUS_MATCH_RULE (link->data))) {
            bus_match_rule_add_recipient (BUS_MATCH_RULE (link->data), connection);
            g_object_unref (rule);
            rule = NULL;
            break;
        }
    }

    if (rule) {
        bus_match_rule_add_recipient (rule, connection);
        dbus->rules = g_list_append (dbus->rules, rule);
        g_signal_connect (rule, "destroy", G_CALLBACK (_rule_destroy_cb), dbus);
    }

    reply_message = ibus_message_new_method_return (message);
    return reply_message;
}
コード例 #14
0
ファイル: dbusimpl.c プロジェクト: iwaim/ibus
static IBusMessage *
_dbus_get_name_owner (BusDBusImpl   *dbus,
                      IBusMessage   *message,
                      BusConnection *connection)
{
    gchar *name;
    BusConnection *owner;
    gboolean retval;
    const gchar *owner_name = NULL;
    IBusMessage *reply_message;
    IBusError *error;

    retval = ibus_message_get_args (message,
                                    &error,
                                    G_TYPE_STRING, &name,
                                    G_TYPE_INVALID);

    if (! retval) {
        reply_message = ibus_message_new_error (message,
                                                error->name,
                                                error->message);
        ibus_error_free (error);
        return reply_message;
    }

    if (g_strcmp0 (name, DBUS_SERVICE_DBUS) == 0 ||
        g_strcmp0 (name, IBUS_SERVICE_IBUS) == 0) {
        owner_name = name;
    }
    else {
        owner = bus_dbus_impl_get_connection_by_name (dbus, name);
        if (owner != NULL) {
            owner_name = bus_connection_get_unique_name (owner);
        }
    }

    if (owner_name != NULL) {
        reply_message = ibus_message_new_method_return (message);
        ibus_message_append_args (reply_message,
                                  G_TYPE_STRING, &owner_name,
                                  G_TYPE_INVALID);
    }
    else {
        reply_message = ibus_message_new_error_printf (message,
                                                       DBUS_ERROR_NAME_HAS_NO_OWNER,
                                                       "Name '%s' does have owner",
                                                       name);
    }

    return reply_message;
}
コード例 #15
0
ファイル: engineproxy.c プロジェクト: hychen/ibus
static void
bus_engine_proxy_process_key_event_reply_cb (IBusPendingCall *pending,
                                             CallData        *call_data)
{
    IBusMessage *reply_message;
    IBusError *error;
    gboolean retval = FALSE;

    reply_message = dbus_pending_call_steal_reply (pending);

    if (reply_message == NULL) {
        /* reply timeout */
        IBusObject *connection;
        connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)call_data->engine);
        ibus_object_destroy (connection);
        goto _out;
    }
    else if ((error = ibus_error_new_from_message (reply_message)) != NULL) {
        if (g_strcmp0 (error->name, DBUS_ERROR_NO_REPLY) == 0) {
            /* reply timeout */
            IBusObject *connection;
            connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)call_data->engine);
            if (connection) {
                ibus_object_destroy (connection);
            }
        }
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        goto _out;
    }

    if (!ibus_message_get_args (reply_message,
                                &error,
                                G_TYPE_BOOLEAN, &retval,
                                G_TYPE_INVALID)) {
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        goto _out;
    }

_out:
    if (reply_message) {
        ibus_message_unref (reply_message);
    }
    g_object_unref (call_data->engine);
    call_data->func (GINT_TO_POINTER (retval), call_data->user_data);
    g_slice_free (CallData, call_data);
}
コード例 #16
0
ファイル: ibusconfig.c プロジェクト: colorant/ibus
gboolean
ibus_config_get_value (IBusConfig  *config,
                       const gchar *section,
                       const gchar *name,
                       GValue      *value)
{
    g_assert (IBUS_IS_CONFIG (config));
    g_assert (section != NULL);
    g_assert (name != NULL);
    g_assert (value != NULL);

    IBusMessage *reply;
    IBusError *error;
    gboolean retval;

    reply = ibus_proxy_call_with_reply_and_block ((IBusProxy *) config,
                                                  "GetValue",
                                                  -1,
                                                  &error,
                                                  G_TYPE_STRING, &section,
                                                  G_TYPE_STRING, &name,
                                                  G_TYPE_INVALID);
    if (reply == NULL) {
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return FALSE;
    }

    if ((error = ibus_error_new_from_message (reply)) != NULL) {
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        ibus_message_unref (reply);
        return FALSE;
    }

    retval = ibus_message_get_args (reply,
                                    &error,
                                    G_TYPE_VALUE, value,
                                    G_TYPE_INVALID);
    ibus_message_unref (reply);
    if (!retval) {
        g_warning ("%s: %s", error->name, error->message);
        return FALSE;
    }

    return TRUE;
}
コード例 #17
0
ファイル: dbusimpl.c プロジェクト: iwaim/ibus
static IBusMessage *
_dbus_remove_match (BusDBusImpl     *dbus,
                    IBusMessage     *message,
                    BusConnection   *connection)
{
    IBusMessage *reply_message;
    IBusError *error;
    gchar *rule_text;
    BusMatchRule *rule;
    GList *link;

    if (!ibus_message_get_args (message,
                                &error,
                                G_TYPE_STRING, &rule_text,
                                G_TYPE_INVALID)) {
        reply_message = ibus_message_new_error (message,
                                                error->name,
                                                error->message);
        ibus_error_free (error);
        return reply_message;
    }

    rule = bus_match_rule_new (rule_text);

    if (rule == NULL ) {
         reply_message = ibus_message_new_error_printf (message,
                                                        DBUS_ERROR_MATCH_RULE_INVALID,
                                                        "Parse rule [%s] failed",
                                                        rule_text);
        return reply_message;
    }

    for (link = dbus->rules; link != NULL; link = link->next) {
        if (bus_match_rule_is_equal (rule, BUS_MATCH_RULE (link->data))) {
            bus_match_rule_remove_recipient (BUS_MATCH_RULE (link->data), connection);
            break;
        }
    }

    g_object_unref (rule);

    reply_message = ibus_message_new_method_return (message);
    return reply_message;
}
コード例 #18
0
ファイル: ibusconfig.c プロジェクト: colorant/ibus
static gboolean
ibus_config_ibus_signal (IBusProxy     *proxy,
                         IBusMessage   *message)
{
    g_assert (IBUS_IS_CONFIG (proxy));
    g_assert (message != NULL);

    IBusConfig *config;
    config = IBUS_CONFIG (proxy);

    if (ibus_message_is_signal (message, IBUS_INTERFACE_CONFIG, "ValueChanged")) {
        gchar *section;
        gchar *name;
        GValue value = { 0 };
        IBusError *error = NULL;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_STRING, &section,
                                        G_TYPE_STRING, &name,
                                        G_TYPE_VALUE, &value,
                                        G_TYPE_INVALID);
        if (!retval) {
            g_warning ("%s: Can not parse arguments of ValueChanges.", DBUS_ERROR_INVALID_ARGS);
            return FALSE;
        }

        g_signal_emit (config,
                       config_signals[VALUE_CHANGED],
                       0,
                       section,
                       name,
                       &value);
        g_value_unset (&value);

        g_signal_stop_emission_by_name (config, "ibus-signal");

        return TRUE;
    }

    return FALSE;
}
コード例 #19
0
ファイル: dbusimpl.c プロジェクト: iwaim/ibus
static IBusMessage *
_dbus_name_has_owner (BusDBusImpl   *dbus,
                      IBusMessage   *message,
                      BusConnection *connection)
{
    gchar *name;
    gboolean retval;
    gboolean has_owner;
    IBusMessage *reply_message;
    IBusError *error;

    retval = ibus_message_get_args (message,
                                    &error,
                                    G_TYPE_STRING, &name,
                                    G_TYPE_INVALID);

    if (! retval) {
        reply_message = ibus_message_new_error (message,
                                                error->name,
                                                error->message);
        ibus_error_free (error);
        return reply_message;
    }

    if (name[0] == ':') {
        has_owner = g_hash_table_lookup (dbus->unique_names, name) != NULL;
    }
    else {
        has_owner = g_hash_table_lookup (dbus->names, name) != NULL;
    }

    reply_message = ibus_message_new_method_return (message);
    ibus_message_append_args (reply_message,
                              G_TYPE_BOOLEAN, &has_owner,
                              G_TYPE_INVALID);

    return reply_message;
}
コード例 #20
0
ファイル: ibusproxy.c プロジェクト: BBIO/ibus
gboolean
ibus_proxy_handle_signal (IBusProxy     *proxy,
                          DBusMessage   *message)
{
    g_assert (IBUS_IS_PROXY (proxy));
    g_assert (message != NULL);

    gboolean retval = FALSE;
    IBusProxyPrivate *priv;
    priv = IBUS_PROXY_GET_PRIVATE (proxy);

    if (ibus_message_is_signal (message, DBUS_SERVICE_DBUS, "NameOwnerChanged")) {
        gchar *name, *old_name, *new_name;
        IBusError *error;

        if (!ibus_message_get_args (message,
                                    &error,
                                    G_TYPE_STRING, &name,
                                    G_TYPE_STRING, &old_name,
                                    G_TYPE_STRING, &new_name,
                                    G_TYPE_INVALID)) {
            g_warning ("%s :%s", error->name, error->message);
            ibus_error_free (error);
        }

        if (g_strcmp0 (priv->unique_name, old_name) == 0) {
            ibus_object_destroy (IBUS_OBJECT (proxy));
            return FALSE;
        }
    }

    if (g_strcmp0 (ibus_message_get_path (message), priv->path) == 0) {
        g_signal_emit (proxy, proxy_signals[IBUS_SIGNAL], 0, message, &retval);
    }

    return retval;
}
コード例 #21
0
ファイル: ibusbus.c プロジェクト: hychen/ibus
const gchar *
ibus_bus_hello (IBusBus *bus)
{
    g_assert (IBUS_IS_BUS (bus));

    gchar *unique_name = NULL;
    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    IBusBusPrivate *priv;

    priv = IBUS_BUS_GET_PRIVATE (bus);

    g_free (priv->unique_name);
    priv->unique_name = NULL;

    reply = ibus_bus_call_with_reply (bus,
                                      DBUS_SERVICE_DBUS,
                                      DBUS_PATH_DBUS,
                                      DBUS_INTERFACE_DBUS,
                                      "Hello",
                                      G_TYPE_INVALID);

    if (reply) {
        if (ibus_message_get_args (reply, &error, G_TYPE_STRING, &unique_name,
                                   G_TYPE_INVALID)) {
            priv->unique_name = g_strdup (unique_name);
        } else {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return priv->unique_name;
}
コード例 #22
0
ファイル: engineproxy.c プロジェクト: hychen/ibus
static gboolean
bus_engine_proxy_ibus_signal (IBusProxy     *proxy,
                              IBusMessage   *message)
{
    g_assert (BUS_IS_ENGINE_PROXY (proxy));
    g_assert (message != NULL);
    g_assert (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_SIGNAL);

    const gchar *interface;
    const gchar *name;
    BusEngineProxy *engine;
    IBusError *error;
    gint i;

    static const struct {
        const gchar *member;
        const guint signal_id;
    } signals [] = {
        { "ShowPreeditText",        SHOW_PREEDIT_TEXT },
        { "HidePreeditText",        HIDE_PREEDIT_TEXT },
        { "ShowAuxiliaryText",      SHOW_AUXILIARY_TEXT },
        { "HideAuxiliaryText",      HIDE_AUXILIARY_TEXT },
        { "ShowLookupTable",        SHOW_LOOKUP_TABLE },
        { "HideLookupTable",        HIDE_LOOKUP_TABLE },
        { "PageUpLookupTable",      PAGE_UP_LOOKUP_TABLE },
        { "PageDownLookupTable",    PAGE_DOWN_LOOKUP_TABLE },
        { "CursorUpLookupTable",    CURSOR_UP_LOOKUP_TABLE },
        { "CursorDownLookupTable",  CURSOR_DOWN_LOOKUP_TABLE },
    };

    engine = BUS_ENGINE_PROXY (proxy);
    interface = ibus_message_get_interface (message);
    name = ibus_message_get_member (message);

    if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_ENGINE) != 0)
        return FALSE;

    for (i = 0; i < G_N_ELEMENTS (signals); i++) {
        if (g_strcmp0 (name, signals[i].member) == 0) {
            g_signal_emit (engine, engine_signals[signals[i].signal_id], 0);
            goto handled;
        }
    }

    if (g_strcmp0 (name, "CommitText") == 0) {
        IBusText *text;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_TEXT, &text,
                                        G_TYPE_INVALID);
        if (!retval)
            goto failed;
        g_signal_emit (engine, engine_signals[COMMIT_TEXT], 0, text);
        g_object_unref (text);
    }
    else if (g_strcmp0 (name, "ForwardKeyEvent") == 0) {
        guint32 keyval;
        guint32 keycode;
        guint32 states;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_UINT, &keyval,
                                        G_TYPE_UINT, &keycode,
                                        G_TYPE_UINT, &states,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;
        g_signal_emit (engine,
                       engine_signals[FORWARD_KEY_EVENT],
                       0,
                       keyval,
                       keycode,
                       states);
    }
    else if (g_strcmp0 (name, "DeleteSurroundingText") == 0) {
        gint  offset_from_cursor;
        guint nchars;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_INT,  &offset_from_cursor,
                                        G_TYPE_UINT, &nchars,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;
        g_signal_emit (engine, engine_signals[DELETE_SURROUNDING_TEXT], 0, offset_from_cursor, nchars);
    }
    else if (g_strcmp0 (name, "UpdatePreeditText") == 0) {
        IBusText *text;
        gint cursor_pos;
        gboolean visible;
        gboolean retval;
        guint mode;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_TEXT, &text,
                                        G_TYPE_UINT, &cursor_pos,
                                        G_TYPE_BOOLEAN, &visible,
                                        G_TYPE_UINT, &mode,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;

        g_signal_emit (engine, engine_signals[UPDATE_PREEDIT_TEXT], 0,
                        text, cursor_pos, visible, mode);
        if (g_object_is_floating (text))
            g_object_unref (text);
    }
    else if (g_strcmp0 (name, "UpdateAuxiliaryText") == 0) {
        IBusText *text;
        gboolean visible;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_TEXT, &text,
                                        G_TYPE_BOOLEAN, &visible,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;

        g_signal_emit (engine, engine_signals[UPDATE_AUXILIARY_TEXT], 0, text, visible);
        if (g_object_is_floating (text))
            g_object_unref (text);
    }
    else if (g_strcmp0 (name, "UpdateLookupTable") == 0) {
        IBusLookupTable *table;
        gboolean visible;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_LOOKUP_TABLE, &table,
                                        G_TYPE_BOOLEAN, &visible,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;

        g_signal_emit (engine, engine_signals[UPDATE_LOOKUP_TABLE], 0, table, visible);
        if (g_object_is_floating (table))
            g_object_unref (table);
    }
    else if (g_strcmp0 (name, "RegisterProperties") == 0) {
        gboolean retval;
        IBusPropList *prop_list;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_PROP_LIST, &prop_list,
                                        G_TYPE_INVALID);
        if (!retval) {
            goto failed;
        }
        g_signal_emit (engine, engine_signals[REGISTER_PROPERTIES], 0, prop_list);

        if (g_object_is_floating (prop_list))
            g_object_unref (prop_list);

    }
    else if (g_strcmp0 (name, "UpdateProperty") == 0) {
        IBusProperty *prop;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_PROPERTY, &prop,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;

        g_signal_emit (engine, engine_signals[UPDATE_PROPERTY], 0, prop);
        if (g_object_is_floating (prop))
            g_object_unref (prop);
    }
    else
        return FALSE;

handled:
    g_signal_stop_emission_by_name (engine, "ibus-signal");
    return TRUE;

failed:
    g_warning ("%s: %s", error->name, error->message);
    ibus_error_free (error);
    return FALSE;
}
コード例 #23
0
ファイル: panelproxy.c プロジェクト: hychen/ibus
static gboolean
bus_panel_proxy_ibus_signal (IBusProxy      *proxy,
                             IBusMessage    *message)
{
    g_assert (BUS_IS_PANEL_PROXY (proxy));
    g_assert (message != NULL);

    BusPanelProxy *panel;
    IBusError *error;
    gint i;

    static const struct {
        const gchar *member;
        const guint signal_id;
    } signals [] = {
        { "PageUp",         PAGE_UP },
        { "PageDown",       PAGE_DOWN },
        { "CursorUp",       CURSOR_UP },
        { "CursorDown",     CURSOR_DOWN },
    };

    panel = BUS_PANEL_PROXY (proxy);

    for (i = 0; i < G_N_ELEMENTS (signals); i++) {
        if (ibus_message_is_signal (message, IBUS_INTERFACE_PANEL, signals[i].member)) {
            g_signal_emit (panel, panel_signals[signals[i].signal_id], 0);
            goto handled;
        }
    }

    if (ibus_message_is_signal (message, IBUS_INTERFACE_PANEL, "CandidateClicked")) {
        guint index, button, state;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_UINT, &index,
                                        G_TYPE_UINT, &button,
                                        G_TYPE_UINT, &state,
                                        G_TYPE_INVALID);
        if (!retval)
            goto failed;

        g_signal_emit (panel, panel_signals[CANDIDATE_CLICKED], 0, index, button, state);
    }
    else if (ibus_message_is_signal (message, IBUS_INTERFACE_PANEL, "PropertyActivate")) {
        gchar *prop_name;
        gint prop_state;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_STRING, &prop_name,
                                        G_TYPE_INT, &prop_state,
                                        G_TYPE_INVALID);
        if (!retval)
            goto failed;

        g_signal_emit (panel, panel_signals[PROPERTY_ACTIVATE], 0, prop_name, prop_state);
    }
    else if (ibus_message_is_signal (message, IBUS_INTERFACE_PANEL, "PropertyShow")) {
        gchar *prop_name;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_STRING, &prop_name,
                                        G_TYPE_INVALID);
        if (!retval)
            goto failed;
        g_signal_emit (panel, panel_signals[PROPERTY_SHOW], 0, prop_name);
    }
    else if (ibus_message_is_signal (message, IBUS_INTERFACE_PANEL, "PropertyHide")) {
        gchar *prop_name;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_STRING, &prop_name,
                                        G_TYPE_INVALID);
        if (!retval)
            goto failed;
        g_signal_emit (panel, panel_signals[PROPERTY_HIDE], 0, prop_name);
    }

handled:
    g_signal_stop_emission_by_name (panel, "ibus-signal");
    return TRUE;

failed:
    g_warning ("%s: %s", error->name, error->message);
    ibus_error_free (error);
    return FALSE;
}
コード例 #24
0
ファイル: factoryproxy.c プロジェクト: luoxsbupt/ibus
BusEngineProxy *
bus_factory_proxy_create_engine (BusFactoryProxy *factory,
                                 IBusEngineDesc  *desc)
{
    g_assert (BUS_IS_FACTORY_PROXY (factory));
    g_assert (IBUS_IS_ENGINE_DESC (desc));

    IBusPendingCall *pending = NULL;
    IBusMessage *reply_message;
    IBusError *error;
    BusEngineProxy *engine;
    gchar *object_path;
    gboolean retval;

    if (g_list_find (factory->component->engines, desc) == NULL) {
        return NULL;
    }

    retval = ibus_proxy_call_with_reply ((IBusProxy *) factory,
                                         "CreateEngine",
                                         &pending,
                                         g_dbus_timeout,
                                         &error,
                                         G_TYPE_STRING, &(desc->name),
                                         G_TYPE_INVALID);

    if (!retval) {
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return NULL;
    }

    ibus_pending_call_wait (pending);
    reply_message = ibus_pending_call_steal_reply (pending);
    ibus_pending_call_unref (pending);

    if (reply_message == NULL) {
        IBusObject *connection;
        connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)factory);
        ibus_object_destroy (connection);
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return NULL;
    }

    if ((error = ibus_error_new_from_message (reply_message)) != NULL) {
        if (g_strcmp0 (error->name, DBUS_ERROR_NO_REPLY) == 0) {
            IBusObject *connection;
            connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)factory);
            ibus_object_destroy (connection);
        }
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        ibus_message_unref (reply_message);
        return NULL;
    }

    if (!ibus_message_get_args (reply_message,
                                &error,
                                IBUS_TYPE_OBJECT_PATH, &object_path,
                                G_TYPE_INVALID)) {
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        ibus_message_unref (reply_message);

        return NULL;
    }

    IBusConnection *connection = ibus_proxy_get_connection ((IBusProxy *) factory);
    engine = bus_engine_proxy_new (object_path, desc, (BusConnection *) connection);
    ibus_message_unref (reply_message);

    return engine;
}
コード例 #25
0
ファイル: engineproxy.c プロジェクト: XueWei/ibus
static gboolean
bus_engine_proxy_ibus_signal (IBusProxy     *proxy,
                              IBusMessage   *message)
{
    g_assert (BUS_IS_ENGINE_PROXY (proxy));
    g_assert (message != NULL);

    BusEngineProxy *engine;
    IBusError *error;
    gint i;

    static const struct {
        const gchar *member;
        const guint signal_id;
    } signals [] = {
        { "ShowPreeditText",        SHOW_PREEDIT_TEXT },
        { "HidePreeditText",        HIDE_PREEDIT_TEXT },
        { "ShowAuxiliaryText",      SHOW_AUXILIARY_TEXT },
        { "HideAuxiliaryText",      HIDE_AUXILIARY_TEXT },
        { "ShowLookupTable",        SHOW_LOOKUP_TABLE },
        { "HideLookupTable",        HIDE_LOOKUP_TABLE },
        { "PageUpLookupTable",      PAGE_UP_LOOKUP_TABLE },
        { "PageDownLookupTable",    PAGE_DOWN_LOOKUP_TABLE },
        { "CursorUpLookupTable",    CURSOR_UP_LOOKUP_TABLE },
        { "CursorDownLookupTable",  CURSOR_DOWN_LOOKUP_TABLE },
        { NULL, 0},
    };

    engine = BUS_ENGINE_PROXY (proxy);

    for (i = 0; ; i++) {
        if (signals[i].member == NULL)
            break;
        if (ibus_message_is_signal (message, IBUS_INTERFACE_ENGINE, signals[i].member)) {
            g_signal_emit (engine, engine_signals[signals[i].signal_id], 0);
            goto handled;
        }
    }

    if (ibus_message_is_signal (message, IBUS_INTERFACE_ENGINE, "CommitText")) {
        IBusText *text;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_TEXT, &text,
                                        G_TYPE_INVALID);
        if (!retval)
            goto failed;
        g_signal_emit (engine, engine_signals[COMMIT_TEXT], 0, text);
        g_object_unref (text);
    }
    else if (ibus_message_is_signal (message, IBUS_INTERFACE_ENGINE, "ForwardKeyEvent")) {
        guint32 keyval;
        guint32 keycode;
        guint32 states;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_UINT, &keyval,
                                        G_TYPE_UINT, &keycode,
                                        G_TYPE_UINT, &states,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;
        g_signal_emit (engine,
                       engine_signals[FORWARD_KEY_EVENT],
                       keyval,
                       keycode,
                       states);
    }
    else if (ibus_message_is_signal (message, IBUS_INTERFACE_ENGINE, "UpdatePreeditText")) {
        IBusText *text;
        gint cursor_pos;
        gboolean visible;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_TEXT, &text,
                                        G_TYPE_UINT, &cursor_pos,
                                        G_TYPE_BOOLEAN, &visible,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;

        g_signal_emit (engine, engine_signals[UPDATE_PREEDIT_TEXT], 0,
                       text, cursor_pos, visible);
        g_object_unref (text);
    }
    else if (ibus_message_is_signal (message, IBUS_INTERFACE_ENGINE, "UpdateAuxiliaryText")) {
        IBusText *text;
        gboolean visible;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_TEXT, &text,
                                        G_TYPE_BOOLEAN, &visible,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;

        g_signal_emit (engine, engine_signals[UPDATE_AUXILIARY_TEXT], 0, text, visible);
        g_object_unref (text);
    }
    else if (ibus_message_is_signal (message, IBUS_INTERFACE_ENGINE, "UpdateLookupTable")) {
        IBusLookupTable *table;
        gboolean visible;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_LOOKUP_TABLE, &table,
                                        G_TYPE_BOOLEAN, &visible,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;

        g_signal_emit (engine, engine_signals[UPDATE_LOOKUP_TABLE], 0, table, visible);
        g_object_unref (table);
    }
    else if (ibus_message_is_signal (message, IBUS_INTERFACE_ENGINE, "RegisterProperties")) {
        gboolean retval;

        if (engine->prop_list) {
            g_object_unref (engine->prop_list);
            engine->prop_list = NULL;
        }

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_PROP_LIST, &engine->prop_list,
                                        G_TYPE_INVALID);
        if (!retval) {
            engine->prop_list = NULL;
            goto failed;
        }
        g_signal_emit (engine, engine_signals[REGISTER_PROPERTIES], 0, engine->prop_list);
    }
    else if (ibus_message_is_signal (message, IBUS_INTERFACE_ENGINE, "UpdateProperty")) {
        IBusProperty *prop;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_PROPERTY, &prop,
                                        G_TYPE_INVALID);

        if (!retval)
            goto failed;

        g_signal_emit (engine, engine_signals[UPDATE_PROPERTY], 0, prop);
        g_object_unref (prop);
    }
    else {
        return FALSE;
    }

handled:
    g_signal_stop_emission_by_name (engine, "ibus-signal");
    return TRUE;

failed:
    g_warning ("%s: %s", error->name, error->message);
    ibus_error_free (error);
    return FALSE;
}
コード例 #26
0
ファイル: ibuspanelservice.c プロジェクト: BBIO/ibus
static gboolean
ibus_panel_service_ibus_message (IBusPanelService *panel,
                                 IBusConnection   *connection,
                                 IBusMessage      *message)
{
    g_assert (IBUS_IS_PANEL_SERVICE (panel));
    g_assert (IBUS_IS_CONNECTION (connection));
    g_assert (message != NULL);

    const static struct {
        const gchar *name;
        const gint offset;
    } no_arg_methods [] = {
        { "CursorUpLookupTable"  , G_STRUCT_OFFSET (IBusPanelServiceClass, cursor_down_lookup_table) },
        { "CursorDownLookupTable", G_STRUCT_OFFSET (IBusPanelServiceClass, cursor_up_lookup_table) },
        { "Destroy",               G_STRUCT_OFFSET (IBusPanelServiceClass, destroy) },
        { "HideAuxiliaryText",     G_STRUCT_OFFSET (IBusPanelServiceClass, hide_auxiliary_text) },
        { "HideLanguageBar",       G_STRUCT_OFFSET (IBusPanelServiceClass, hide_language_bar) },
        { "HideLookupTable",       G_STRUCT_OFFSET (IBusPanelServiceClass, hide_lookup_table) },
        { "HidePreeditText",       G_STRUCT_OFFSET (IBusPanelServiceClass, hide_preedit_text) },
        { "PageDownLookupTable",   G_STRUCT_OFFSET (IBusPanelServiceClass, page_down_lookup_table) },
        { "PageUpLookupTable",     G_STRUCT_OFFSET (IBusPanelServiceClass, page_up_lookup_table) },
        { "Reset",                 G_STRUCT_OFFSET (IBusPanelServiceClass, reset) },
        { "ShowAuxiliaryText",     G_STRUCT_OFFSET (IBusPanelServiceClass, show_auxiliary_text) },
        { "ShowLanguageBar",       G_STRUCT_OFFSET (IBusPanelServiceClass, show_language_bar) },
        { "ShowLookupTable",       G_STRUCT_OFFSET (IBusPanelServiceClass, show_lookup_table) },
        { "ShowPreeditText",       G_STRUCT_OFFSET (IBusPanelServiceClass, show_preedit_text) },
        { "StartSetup",            G_STRUCT_OFFSET (IBusPanelServiceClass, start_setup) },
        { "StateChanged",          G_STRUCT_OFFSET (IBusPanelServiceClass, state_changed) },
    };

    IBusMessage *reply = NULL;

    gint i;
    for (i = 0; i < G_N_ELEMENTS (no_arg_methods); i++) {
        if (!ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL,
                                          no_arg_methods[i].name))
            continue;

        IBusMessageIter iter;
        ibus_message_iter_init (message, &iter);
        if (ibus_message_iter_has_next (&iter)) {
            reply = ibus_message_new_error_printf (message,
                                                   DBUS_ERROR_INVALID_ARGS,
                                                   "%s.%s: Method does not have arguments",
                                                   IBUS_INTERFACE_PANEL,
                                                   no_arg_methods[i].name);
        }
        else {
            IBusError *error = NULL;
            typedef gboolean (* NoArgFunc) (IBusPanelService *, IBusError **);
            NoArgFunc func;
            func = G_STRUCT_MEMBER (NoArgFunc,
                                    IBUS_PANEL_SERVICE_GET_CLASS (panel),
                                    no_arg_methods[i].offset);
            if (!func (panel, &error)) {
                reply = ibus_message_new_error (message,
                                                error->name,
                                                error->message);
                ibus_error_free (error);
            }
            else {
                reply = ibus_message_new_method_return (message);
            }
        }
        ibus_connection_send (connection, reply);
        ibus_message_unref (reply);
        return TRUE;
    }

    if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "FocusIn")) {
        const gchar* input_context_path = NULL;
        IBusError *error = NULL;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_OBJECT_PATH,
                                        &input_context_path,
                                        G_TYPE_INVALID);

        if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->focus_in (panel,
                                                                        input_context_path,
                                                                        &error)) {
            reply = ibus_message_new_error (message,
                                            error->name,
                                            error->message);
            ibus_error_free (error);
        }
        else {
            reply = ibus_message_new_method_return (message);
        }
    }
    else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "FocusOut")) {
        const gchar* input_context_path = NULL;
        gboolean retval;
        IBusError *error = NULL;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_OBJECT_PATH,
                                        &input_context_path,
                                        G_TYPE_INVALID);

        if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->focus_out (panel,
                                                                         input_context_path,
                                                                         &error)) {
            reply = ibus_message_new_error(message,
                                           error->name,
                                           error->message);
            ibus_error_free (error);
        }
        else {
            reply = ibus_message_new_method_return (message);
        }
    }
    else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "RegisterProperties")) {
        IBusPropList *prop_list = NULL;
        gboolean retval;
        IBusError *error = NULL;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_PROP_LIST, &prop_list,
                                        G_TYPE_INVALID);

        if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->register_properties (panel,
                                                                                   prop_list,
                                                                                   &error)) {
            reply = ibus_message_new_error(message,
                                           error->name,
                                           error->message);
            ibus_error_free (error);
        }
        else {
            reply = ibus_message_new_method_return (message);
        }

        if (prop_list != NULL && g_object_is_floating (prop_list))
            g_object_unref (prop_list);
    }
    else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateAuxiliaryText")) {
        IBusText *text = NULL;
        gboolean visible;
        gboolean retval;
        IBusError *error = NULL;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_TEXT, &text,
                                        G_TYPE_BOOLEAN, &visible,
                                        G_TYPE_INVALID);

        if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_auxiliary_text (panel,
                                                                                     text,
                                                                                     visible,
                                                                                     &error)) {
            reply = ibus_message_new_error(message,
                                           error->name,
                                           error->message);
            ibus_error_free (error);
        }
        else {
            reply = ibus_message_new_method_return (message);
        }

        if (text != NULL && g_object_is_floating (text))
            g_object_unref (text);
    }
    else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateLookupTable")) {
        IBusLookupTable *table = NULL;
        gboolean visible = FALSE;
        gboolean retval;
        IBusError *error = NULL;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_LOOKUP_TABLE, &table,
                                        G_TYPE_BOOLEAN, &visible,
                                        G_TYPE_INVALID);

        if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_lookup_table (panel,
                                                                                   table,
                                                                                   visible,
                                                                                   &error)) {
            reply = ibus_message_new_error(message,
                                           error->name,
                                           error->message);
            ibus_error_free (error);
        }
        else {
            reply = ibus_message_new_method_return (message);
        }

        if (table != NULL && g_object_is_floating (table))
            g_object_unref (table);
    }
    else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdatePreeditText")) {
        IBusText *text = NULL;
        guint cursor_pos;
        gboolean visible;
        gboolean retval;
        IBusError *error = NULL;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_TEXT, &text,
                                        G_TYPE_UINT, &cursor_pos,
                                        G_TYPE_BOOLEAN, &visible,
                                        G_TYPE_INVALID);

        if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_preedit_text (panel,
                                                                                   text,
                                                                                   cursor_pos,
                                                                                   visible,
                                                                                   &error)) {
            reply = ibus_message_new_error(message,
                                           error->name,
                                           error->message);
            ibus_error_free (error);
        }
        else {
            reply = ibus_message_new_method_return (message);
        }

        if (text != NULL && g_object_is_floating (text))
            g_object_unref (text);
    }
    else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateProperty")) {
        IBusProperty *property = NULL;
        gboolean retval;
        IBusError *error = NULL;

        retval = ibus_message_get_args (message,
                                        &error,
                                        IBUS_TYPE_PROPERTY, &property,
                                        G_TYPE_INVALID);

        if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_property (panel,
                                                                               property,
                                                                               &error)) {
            reply = ibus_message_new_error(message,
                                           error->name,
                                           error->message);
            ibus_error_free (error);
        }
        else {
            reply = ibus_message_new_method_return (message);
        }

        if (property != NULL && g_object_is_floating (property))
            g_object_unref (property);
    }
    else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "SetCursorLocation")) {
        guint x, y, w, h;
        gboolean retval;
        IBusError *error = NULL;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_INT, &x,
                                        G_TYPE_INT, &y,
                                        G_TYPE_INT, &w,
                                        G_TYPE_INT, &h,
                                        G_TYPE_INVALID);

        if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->set_cursor_location (panel,
                                                                                   x,
                                                                                   y,
                                                                                   w,
                                                                                   h,
                                                                                   &error)) {
            reply = ibus_message_new_error(message,
                                           error->name,
                                           error->message);
            ibus_error_free (error);
        }
        else {
            reply = ibus_message_new_method_return (message);
        }
    }

    if (reply) {
        ibus_connection_send (connection, reply);
        ibus_message_unref (reply);
        return TRUE;
    }

    return TRUE;
}
コード例 #27
0
ファイル: ibusfactory.c プロジェクト: hychen/ibus
static gboolean
ibus_factory_ibus_message (IBusFactory    *factory,
                           IBusConnection *connection,
                           IBusMessage    *message)
{
    g_assert (IBUS_IS_FACTORY (factory));
    g_assert (IBUS_IS_CONNECTION (connection));
    g_assert (message != NULL);

    IBusMessage *reply_message;
    IBusFactoryPrivate *priv;
    priv = IBUS_FACTORY_GET_PRIVATE (factory);

    g_assert (priv->connection == connection);

    if (ibus_message_is_method_call (message,
                                     IBUS_INTERFACE_FACTORY,
                                     "CreateEngine")) {
        gchar *engine_name;
        gchar *path;
        IBusError *error;
        IBusEngine *engine;
        gboolean retval;
        GType engine_type;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_STRING, &engine_name,
                                        G_TYPE_INVALID);

        if (!retval) {
            reply_message = ibus_message_new_error_printf (message,
                                        DBUS_ERROR_INVALID_ARGS,
                                        "The 1st arg should be engine name");
            ibus_connection_send (connection, reply_message);
            ibus_message_unref (reply_message);
            return TRUE;
        }

        engine_type = (GType )g_hash_table_lookup (priv->engine_table, engine_name);

        if (engine_type == G_TYPE_INVALID) {
             reply_message = ibus_message_new_error_printf (message,
                                        DBUS_ERROR_FAILED,
                                        "Can not create engine %s", engine_name);
            ibus_connection_send (connection, reply_message);
            ibus_message_unref (reply_message);
            return TRUE;

        }

        path = g_strdup_printf ("/org/freedesktop/IBus/Engine/%d", ++priv->id);

        engine = g_object_new (engine_type,
                               "name", engine_name,
                               "path", path,
                               "connection", priv->connection,
                               NULL);

        priv->engine_list = g_list_append (priv->engine_list, engine);
        g_signal_connect (engine,
                          "destroy",
                          G_CALLBACK (_engine_destroy_cb),
                          factory);

        reply_message = ibus_message_new_method_return (message);
        ibus_message_append_args (reply_message,
                                  IBUS_TYPE_OBJECT_PATH, &path,
                                  G_TYPE_INVALID);
        g_free (path);
        ibus_connection_send (connection, reply_message);
        ibus_message_unref (reply_message);
        return TRUE;
    }

    return IBUS_SERVICE_CLASS (ibus_factory_parent_class)->ibus_message (
                                (IBusService *)factory,
                                connection,
                                message);
}
コード例 #28
0
ファイル: ibusengine.c プロジェクト: definite/ibus
static gboolean
ibus_engine_ibus_message (IBusEngine     *engine,
                          IBusConnection *connection,
                          IBusMessage    *message)
{
    g_assert (IBUS_IS_ENGINE (engine));
    g_assert (IBUS_IS_CONNECTION (connection));
    g_assert (message != NULL);
    g_assert (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL);

    IBusEnginePrivate *priv;
    priv = IBUS_ENGINE_GET_PRIVATE (engine);

    g_assert (priv->connection == connection);

    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    gboolean retval;

    gint i;
    const gchar *interface;
    const gchar *name;

    static const struct {
        gchar *member;
        guint  signal_id;
    } no_arg_methods[] = {
        { "FocusIn",     FOCUS_IN },
        { "FocusOut",    FOCUS_OUT },
        { "Reset",       RESET },
        { "Enable",      ENABLE },
        { "Disable",     DISABLE },
        { "PageUp",      PAGE_UP },
        { "PageDown",    PAGE_DOWN },
        { "CursorUp",    CURSOR_UP },
        { "CursorDown",  CURSOR_DOWN },
    };

    interface = ibus_message_get_interface (message);
    name = ibus_message_get_member (message);

    if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_ENGINE) != 0)
        return IBUS_SERVICE_CLASS (ibus_engine_parent_class)->ibus_message (
                        (IBusService *) engine, connection, message);

    do {
        if (g_strcmp0 (name, "ProcessKeyEvent") == 0) {
            guint keyval, keycode, state;

            retval = ibus_message_get_args (message,
                                            &error,
                                            G_TYPE_UINT, &keyval,
                                            G_TYPE_UINT, &keycode,
                                            G_TYPE_UINT, &state,
                                            G_TYPE_INVALID);

            if (!retval) {
                reply = ibus_message_new_error_printf (message,
                                DBUS_ERROR_INVALID_ARGS,
                                "%s.%s: Can not match signature (uuu) of method",
                                IBUS_INTERFACE_ENGINE, "ProcessKeyEvent");
                ibus_error_free (error);
            }
            else {
                retval = FALSE;
                g_signal_emit (engine,
                               engine_signals[PROCESS_KEY_EVENT],
                               0,
                               keyval,
                               keycode,
                               state,
                               &retval);

                reply = ibus_message_new_method_return (message);
                ibus_message_append_args (reply,
                                          G_TYPE_BOOLEAN, &retval,
                                          G_TYPE_INVALID);
            }
            break;
        }

        for (i = 0;
             i < G_N_ELEMENTS (no_arg_methods) && g_strcmp0 (name, no_arg_methods[i].member) != 0;
             i++);

        if (i < G_N_ELEMENTS (no_arg_methods)) {
            IBusMessageIter iter;
            ibus_message_iter_init (message, &iter);
            if (ibus_message_iter_has_next (&iter)) {
                reply = ibus_message_new_error_printf (message,
                                    DBUS_ERROR_INVALID_ARGS,
                                    "%s.%s: Method does not have arguments",
                                    IBUS_INTERFACE_ENGINE, no_arg_methods[i].member);
            }
            else {
                g_signal_emit (engine, engine_signals[no_arg_methods[i].signal_id], 0);
                reply = ibus_message_new_method_return (message);
            }
            break;
        }

        if (g_strcmp0 (name, "CandidateClicked") == 0) {
            guint index, button, state;

            retval = ibus_message_get_args (message,
                                            &error,
                                            G_TYPE_UINT, &index,
                                            G_TYPE_UINT, &button,
                                            G_TYPE_UINT, &state,
                                            G_TYPE_INVALID);

            if (!retval) {
                reply = ibus_message_new_error_printf (message,
                                DBUS_ERROR_INVALID_ARGS,
                                "%s.%s: Can not match signature (uuu) of method",
                                IBUS_INTERFACE_ENGINE, "CandidateClicked");
                ibus_error_free (error);
            }
            else {
                g_signal_emit (engine,
                               engine_signals[CANDIDATE_CLICKED],
                               0,
                               index,
                               button,
                               state);
                reply = ibus_message_new_method_return (message);
            }
        }
        else if (g_strcmp0 (name, "PropertyActivate") == 0) {
            gchar *name;
            guint state;

            retval = ibus_message_get_args (message,
                                            &error,
                                            G_TYPE_STRING, &name,
                                            G_TYPE_UINT, &state,
                                            G_TYPE_INVALID);

            if (!retval) {
                reply = ibus_message_new_error_printf (message,
                                DBUS_ERROR_INVALID_ARGS,
                                "%s.%s: Can not match signature (si) of method",
                                IBUS_INTERFACE_ENGINE,
                                "PropertyActivate");
                ibus_error_free (error);
            }
            else {
                g_signal_emit (engine,
                               engine_signals[PROPERTY_ACTIVATE],
                               0,
                               name,
                               state);

                reply = ibus_message_new_method_return (message);
            }
        }
        else if (g_strcmp0 (name, "PropertyShow") == 0) {
            gchar *name;

            retval = ibus_message_get_args (message,
                                            &error,
                                            G_TYPE_STRING, &name,
                                            G_TYPE_INVALID);

            if (!retval) {
                reply = ibus_message_new_error_printf (message,
                            DBUS_ERROR_INVALID_ARGS,
                            "%s.%s: Can not match signature (s) of method",
                            IBUS_INTERFACE_ENGINE,
                            "PropertyShow");
                ibus_error_free (error);
            }
            else {
                g_signal_emit (engine,
                               engine_signals[PROPERTY_SHOW],
                               0,
                               name);

                reply = ibus_message_new_method_return (message);
            }
        }
        else if (g_strcmp0 (name, "PropertyHide") == 0) {
            gchar *name;

            retval = ibus_message_get_args (message,
                                            &error,
                                            G_TYPE_STRING, &name,
                                            G_TYPE_INVALID);
            if (!retval) {
                reply = ibus_message_new_error_printf (message,
                            DBUS_ERROR_INVALID_ARGS,
                            "%s.%s: Can not match signature (s) of method",
                            IBUS_INTERFACE_ENGINE, "PropertyHide");
                ibus_error_free (error);
            }
            else {
                g_signal_emit (engine, engine_signals[PROPERTY_HIDE], 0, name);
                reply = ibus_message_new_method_return (message);
            }
        }
        else if (g_strcmp0 (name, "SetCursorLocation") == 0) {
            gint x, y, w, h;

            retval = ibus_message_get_args (message,
                                            &error,
                                            G_TYPE_INT, &x,
                                            G_TYPE_INT, &y,
                                            G_TYPE_INT, &w,
                                            G_TYPE_INT, &h,
                                            G_TYPE_INVALID);
            if (!retval) {
                reply = ibus_message_new_error_printf (message,
                            DBUS_ERROR_INVALID_ARGS,
                            "%s.%s: Can not match signature (iiii) of method",
                            IBUS_INTERFACE_ENGINE,
                            "SetCursorLocation");
                ibus_error_free (error);
            }
            else {
                engine->cursor_area.x = x;
                engine->cursor_area.y = y;
                engine->cursor_area.width = w;
                engine->cursor_area.height = h;

                g_signal_emit (engine,
                               engine_signals[SET_CURSOR_LOCATION],
                               0,
                               x, y, w, h);

                reply = ibus_message_new_method_return (message);
            }
        }
        else if (g_strcmp0 (name, "SetCapabilities") == 0) {
            guint caps;

            retval = ibus_message_get_args (message,
                                            &error,
                                            G_TYPE_UINT, &caps,
                                            G_TYPE_INVALID);

            if (!retval) {
                reply = ibus_message_new_error_printf (message,
                            DBUS_ERROR_INVALID_ARGS,
                            "%s.%s: Can not match signature (u) of method",
                            IBUS_INTERFACE_ENGINE, "SetCapabilities");
                ibus_error_free (error);
            }
            else {
                engine->client_capabilities = caps;
                g_signal_emit (engine, engine_signals[SET_CAPABILITIES], 0, caps);
                reply = ibus_message_new_method_return (message);
            }
        }
        else if (g_strcmp0 (name, "Destroy") == 0) {
            reply = ibus_message_new_method_return (message);
            ibus_connection_send (connection, reply);
            ibus_message_unref (reply);
            ibus_object_destroy ((IBusObject *) engine);
            return TRUE;
        }
        else {
            reply = ibus_message_new_error_printf (message,
                        DBUS_ERROR_UNKNOWN_METHOD,
                        "%s.%s",
                        IBUS_INTERFACE_ENGINE, name);
            g_warn_if_reached ();
        }
    } while (0);

    ibus_connection_send (connection, reply);
    ibus_message_unref (reply);
    return TRUE;
}
コード例 #29
0
ファイル: ibusconfigservice.c プロジェクト: colorant/ibus
static gboolean
ibus_config_service_ibus_message (IBusConfigService     *config,
                                  IBusConnection        *connection,
                                  IBusMessage           *message)
{
    g_assert (IBUS_IS_CONFIG_SERVICE (config));
    g_assert (IBUS_IS_CONNECTION (connection));
    g_assert (message != NULL);

    IBusMessage *reply = NULL;

    if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "SetValue")) {
        gchar *section;
        gchar *name;
        GValue value = { 0 };
        IBusError *error = NULL;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_STRING, &section,
                                        G_TYPE_STRING, &name,
                                        G_TYPE_VALUE, &value,
                                        G_TYPE_INVALID);
        if (!retval) {
            reply = ibus_message_new_error_printf (message,
                                                   DBUS_ERROR_INVALID_ARGS,
                                                   "Can not parse arguments 1 of SetValue");
            ibus_error_free (error);
        }
        else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->set_value (config, section, name, &value, &error)) {
            reply = ibus_message_new_error (message,
                                            error->name,
                                            error->message);
            ibus_error_free (error);
        }
        else {
            reply = ibus_message_new_method_return (message);
        }
    }
    else if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "GetValue")) {
        gchar *section;
        gchar *name;
        GValue value = { 0 };
        IBusError *error = NULL;
        gboolean retval;

        retval = ibus_message_get_args (message,
                                        &error,
                                        G_TYPE_STRING, &section,
                                        G_TYPE_STRING, &name,
                                        G_TYPE_INVALID);

        if (!retval) {
            reply = ibus_message_new_error (message,
                                            error->name,
                                            error->message);
            ibus_error_free (error);
        }
        else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->get_value (config, section, name, &value, &error)) {
            reply = ibus_message_new_error (message,
                                            error->name,
                                            error->message);
            ibus_error_free (error);
        }
        else {
            reply = ibus_message_new_method_return (message);
            ibus_message_append_args (reply,
                                      G_TYPE_VALUE, &value,
                                      G_TYPE_INVALID);
            g_value_unset (&value);
        }
    }

    if (reply) {
        ibus_connection_send (connection, reply);
        ibus_message_unref (reply);
        return TRUE;
    }

    return parent_class->ibus_message ((IBusService *) config, connection, message);
}
コード例 #30
0
ファイル: ibusinputcontext.c プロジェクト: BBIO/ibus
gboolean
ibus_input_context_process_key_event (IBusInputContext *context,
                                      guint32           keyval,
                                      guint32           keycode,
                                      guint32           state)
{
    g_assert (IBUS_IS_INPUT_CONTEXT (context));

    IBusMessage *reply_message;
    IBusPendingCall *pending = NULL;
    IBusError *error = NULL;
    gboolean retval;

    if (state & IBUS_HANDLED_MASK)
        return TRUE;

    if (state & IBUS_IGNORED_MASK)
        return FALSE;

    retval = ibus_proxy_call_with_reply ((IBusProxy *) context,
                                         "ProcessKeyEvent",
                                         &pending,
                                         -1,
                                         &error,
                                         G_TYPE_UINT, &keyval,
                                         G_TYPE_UINT, &keycode,
                                         G_TYPE_UINT, &state,
                                         G_TYPE_INVALID);
    if (!retval) {
        g_debug ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return FALSE;
    }

    /* wait reply or timeout */
    IBusConnection *connection = ibus_proxy_get_connection ((IBusProxy *) context);
    while (!ibus_pending_call_get_completed (pending)) {
        ibus_connection_read_write_dispatch (connection, -1);
    }

    reply_message = ibus_pending_call_steal_reply (pending);
    ibus_pending_call_unref (pending);

    if (reply_message == NULL) {
        g_debug ("%s: Do not recevie reply of ProcessKeyEvent", DBUS_ERROR_NO_REPLY);
        retval = FALSE;
    }
    else if ((error = ibus_error_new_from_message (reply_message)) != NULL) {
        g_debug ("%s: %s", error->name, error->message);
        ibus_message_unref (reply_message);
        ibus_error_free (error);
        retval = FALSE;
    }
    else {
        if (!ibus_message_get_args (reply_message,
                                    &error,
                                    G_TYPE_BOOLEAN, &retval,
                                    G_TYPE_INVALID)) {
            g_debug ("%s: %s", error->name, error->message);
            ibus_error_free (error);
            retval = FALSE;
        }
        ibus_message_unref (reply_message);
    }
    return retval;
}