gboolean ibus_proxy_call_with_reply (IBusProxy *proxy, const gchar *method, IBusPendingCall **pending, gint timeout_milliseconds, IBusError **error, GType first_arg_type, ...) { g_assert (IBUS_IS_PROXY (proxy)); g_assert (pending != NULL); g_assert (method != NULL); va_list args; gboolean retval; DBusMessage *message; IBusProxyPrivate *priv; priv = IBUS_PROXY_GET_PRIVATE (proxy); if (priv->connection == NULL || !ibus_connection_is_connected (priv->connection)) { if (error) { *error = ibus_error_new_from_printf (DBUS_ERROR_DISCONNECTED, "Connection of %s was disconnected.", G_OBJECT_TYPE_NAME (proxy)); } return FALSE; } message = ibus_message_new_method_call (priv->name, priv->path, priv->interface, method); va_start (args, first_arg_type); retval = ibus_message_append_args_valist (message, first_arg_type, args); va_end (args); *pending = NULL; retval = ibus_connection_send_with_reply (priv->connection, message, pending, timeout_milliseconds); ibus_message_unref (message); if (!retval && error != NULL) { *error = ibus_error_new_from_printf (DBUS_ERROR_NO_MEMORY, ""); } return retval; }
static gboolean ibus_config_gconf_get_value (IBusConfigService *config, const gchar *section, const gchar *name, GValue *value, IBusError **error) { gchar *key; GConfValue *gv; key = g_strdup_printf (GCONF_PREFIX"/%s/%s", section, name); gv = gconf_client_get (((IBusConfigGConf *) config)->client, key, NULL); g_free (key); if (gv == NULL) { *error = ibus_error_new_from_printf (DBUS_ERROR_FAILED, "Can not get value [%s->%s]", section, name); return FALSE; } _from_gconf_value (value, gv); gconf_value_free (gv); return TRUE; }
static gboolean ibus_panel_service_not_implemented (IBusPanelService *panel, IBusError **error) { if (error) { *error = ibus_error_new_from_printf (DBUS_ERROR_FAILED, "Not implemented"); } return FALSE; }
static gboolean ibus_config_service_unset (IBusConfigService *config, const gchar *section, const gchar *name, IBusError **error) { if (error) { *error = ibus_error_new_from_printf (DBUS_ERROR_FAILED, "Can not unset [%s, %s]", section, name); } return FALSE; }
static GList * ibus_bus_do_list_engines (IBusBus *bus, gboolean active_engines_only) { g_assert (IBUS_IS_BUS (bus)); IBusMessage *message, *reply; IBusError *error; gboolean retval; IBusBusPrivate *priv; IBusMessageIter iter, subiter; GList *engines; const gchar* member = active_engines_only ? "ListActiveEngines" : "ListEngines"; priv = IBUS_BUS_GET_PRIVATE (bus); message = ibus_message_new_method_call (IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, member); reply = ibus_connection_send_with_reply_and_block (priv->connection, message, -1, &error); ibus_message_unref (message); 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_error_free (error); ibus_message_unref (reply); return NULL; } retval = ibus_message_iter_init (reply, &iter); if (!retval) { error = ibus_error_new_from_printf (DBUS_ERROR_INVALID_ARGS, "Message does not have arguments!"); g_warning ("%s : %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply); return NULL; } if (!ibus_message_iter_recurse (&iter, IBUS_TYPE_ARRAY, &subiter)) { ibus_message_unref (reply); return NULL; } engines = NULL; while (ibus_message_iter_get_arg_type (&subiter) != G_TYPE_INVALID) { IBusSerializable *object = NULL; if (!ibus_message_iter_get (&subiter, IBUS_TYPE_ENGINE_DESC, &object) || !object) { g_warning ("Unexpected type is returned from %s", member); continue; } engines = g_list_append (engines, object); ibus_message_iter_next (&subiter); }; ibus_message_unref (reply); return engines; }
gboolean ibus_message_get_args_valist (IBusMessage *message, IBusError **error, GType first_arg_type, va_list va_args) { g_assert (message != NULL); gboolean retval; IBusMessageIter iter; GType type; gpointer value; va_list backup_args; gint i; retval = ibus_message_iter_init (message, &iter); if (!retval) { if (error) { *error = ibus_error_new_from_printf (DBUS_ERROR_INVALID_ARGS, "Message does not have arguments!"); } return FALSE; } va_copy (backup_args, va_args); i = 0; type = first_arg_type; while (type != G_TYPE_INVALID) { value = va_arg (va_args, gpointer); retval = ibus_message_iter_get (&iter, type, value); if (!retval) goto _failed; ibus_message_iter_next (&iter); i ++; type = va_arg (va_args, GType); } va_end (backup_args); return TRUE; _failed: *error = ibus_error_new_from_printf (DBUS_ERROR_INVALID_ARGS, "The argument %d is not %s", i, g_type_name (type)); /* release resources */ type = first_arg_type; while (i > 0) { gpointer *value = va_arg (backup_args, gpointer *); if (g_type_is_a (type, G_TYPE_BOXED)) { g_boxed_free (type, *value); } else if (g_type_is_a (type, G_TYPE_OBJECT)) { g_object_unref (*value); } i --; type = va_arg (backup_args, GType); } va_end (backup_args); return FALSE; }
static gboolean ibus_input_context_ibus_signal (IBusProxy *proxy, IBusMessage *message) { g_assert (IBUS_IS_INPUT_CONTEXT (proxy)); g_assert (message != NULL); g_assert (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_SIGNAL); IBusInputContext *context; IBusError *error = NULL; gint i; const gchar *interface; const gchar *name; context = IBUS_INPUT_CONTEXT (proxy); static const struct { const gchar *member; guint signal_id; } signals [] = { { "Enabled", ENABLED }, { "Disabled", DISABLED }, { "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 }, }; do { interface = ibus_message_get_interface (message); name = ibus_message_get_member (message); if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_INPUT_CONTEXT) != 0) { error = ibus_error_new_from_printf (DBUS_ERROR_FAILED, "Signal %s.%s is not handled", interface, name); break; } 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) { g_signal_emit (context, context_signals[COMMIT_TEXT], 0, text); if (g_object_is_floating (text)) g_object_unref (text); } break; } if (g_strcmp0 (name, "UpdatePreeditText") == 0) { IBusText *text; gint32 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) { g_signal_emit (context, context_signals[UPDATE_PREEDIT_TEXT], 0, text, cursor_pos, visible); if (g_object_is_floating (text)) g_object_unref (text); } break; } for (i = 0; i < G_N_ELEMENTS (signals) && g_strcmp0 (name, signals[i].member) != 0; i++); if (i < G_N_ELEMENTS (signals)) { g_signal_emit (context, context_signals[signals[i].signal_id], 0); break; } 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) { g_signal_emit (context, context_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) { g_signal_emit (context, context_signals[UPDATE_LOOKUP_TABLE], 0, table, visible); if (g_object_is_floating (table)) g_object_unref (table); } } else if (g_strcmp0 (name, "RegisterProperties") == 0) { IBusPropList *prop_list; gboolean retval; retval = ibus_message_get_args (message, &error, IBUS_TYPE_PROP_LIST, &prop_list, G_TYPE_INVALID); if (retval) { g_signal_emit (context, context_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) { g_signal_emit (context, context_signals[UPDATE_PROPERTY], 0, prop); if (g_object_is_floating (prop)) g_object_unref (prop); } } else if (g_strcmp0 (name, "ForwardKeyEvent") == 0) { guint32 keyval; guint32 keycode; guint32 state; gboolean retval; retval = ibus_message_get_args (message, &error, G_TYPE_UINT, &keyval, G_TYPE_UINT, &keycode, G_TYPE_UINT, &state, G_TYPE_INVALID); if (retval) { g_signal_emit (context, context_signals[FORWARD_KEY_EVENT], 0, keyval, keycode, state | IBUS_FORWARD_MASK); } } 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) { g_signal_emit (context, context_signals[DELETE_SURROUNDING_TEXT], 0, offset_from_cursor, nchars); } } else { error = ibus_error_new_from_printf (DBUS_ERROR_FAILED, "Signal %s.%s is not handled", interface, name); break; } } while (0); if (error == NULL) { g_signal_stop_emission_by_name (context, "ibus-signal"); return TRUE; } /* some error happens */ g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); return FALSE; }