diff options
author | fujiwarat <takao.fujiwara1@gmail.com> | 2013-06-14 12:13:13 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2013-06-14 12:13:13 +0900 |
commit | 458945e7308ab2661355edbf6880102c5f628dbe (patch) | |
tree | e1afdfd30134643a6604c067edf00bffa1931c58 /src | |
parent | c9ba5e1d155ab711c68f18d26de38bdba3128f03 (diff) |
Refactor old getter and setter to dbus property in bus/ibusimpl.c
Review URL: https://codereview.appspot.com/9477043
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/ibusbus.c | 249 | ||||
-rw-r--r-- | src/ibusbus.h | 139 | ||||
-rw-r--r-- | src/ibusshare.h | 6 | ||||
-rw-r--r-- | src/tests/Makefile.am | 13 | ||||
-rw-r--r-- | src/tests/ibus-bus.c | 242 |
6 files changed, 585 insertions, 65 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7ee5df87..b2793c8a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,6 +48,7 @@ AM_CPPFLAGS = \ @GOBJECT2_CFLAGS@ \ @GIO2_CFLAGS@ \ -DIBUS_DATA_DIR=\"$(pkgdatadir)\" \ + -DIBUS_DISABLE_DEPRECATION_WARNINGS \ -DIBUS_COMPILATION \ -DISOCODES_PREFIX=\"$(ISOCODES_PREFIX)\" \ $(NULL) diff --git a/src/ibusbus.c b/src/ibusbus.c index 5fa03c3c..fc401f14 100644 --- a/src/ibusbus.c +++ b/src/ibusbus.c @@ -1,8 +1,8 @@ /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ /* vim:set et sts=4: */ /* ibus - The Input Bus - * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com> - * Copyright (C) 2008-2010 Red Hat, Inc. + * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com> + * Copyright (C) 2008-2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -580,10 +580,13 @@ _async_finish_object_path (GAsyncResult *res, GSimpleAsyncResult *simple = (GSimpleAsyncResult *) res; if (g_simple_async_result_propagate_error (simple, error)) return NULL; - GVariant *variant = g_simple_async_result_get_op_res_gpointer (simple); - g_return_val_if_fail (variant != NULL, NULL); + GVariant *result = g_simple_async_result_get_op_res_gpointer (simple); + GVariant *variant = NULL; + g_return_val_if_fail (result != NULL, NULL); gchar *path = NULL; - g_variant_get (variant, "(&o)", &path); + g_variant_get (result, "(v)", &variant); + path = g_variant_dup_string (variant, NULL); + g_variant_unref (variant); return path; } @@ -830,13 +833,18 @@ ibus_bus_current_input_context (IBusBus *bus) result = ibus_bus_call_sync (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "CurrentInputContext", - NULL, - G_VARIANT_TYPE ("(o)")); + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + IBUS_INTERFACE_IBUS, + "CurrentInputContext"), + G_VARIANT_TYPE ("(v)")); if (result != NULL) { - g_variant_get (result, "(o)", &path); + GVariant *variant = NULL; + g_variant_get (result, "(v)", &variant); + path = g_variant_dup_string (variant, NULL); + g_variant_unref (variant); g_variant_unref (result); } @@ -855,10 +863,12 @@ ibus_bus_current_input_context_async (IBusBus *bus, ibus_bus_call_async (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "CurrentInputContext", - NULL, - G_VARIANT_TYPE ("(o)"), + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + IBUS_INTERFACE_IBUS, + "CurrentInputContext"), + G_VARIANT_TYPE ("(v)"), ibus_bus_current_input_context_async, timeout_msec, cancellable, @@ -874,7 +884,7 @@ ibus_bus_current_input_context_async_finish (IBusBus *bus, g_assert (IBUS_IS_BUS (bus)); g_assert (g_simple_async_result_is_valid (res, (GObject *) bus, ibus_bus_current_input_context_async)); - return g_strdup (_async_finish_object_path (res, error)); + return _async_finish_object_path (res, error); } static void @@ -1528,17 +1538,24 @@ ibus_bus_do_list_engines (IBusBus *bus, gboolean active_engines_only) GList *retval = NULL; GVariant *result; + const gchar *property = + active_engines_only ? "ActiveEngines" : "Engines"; result = ibus_bus_call_sync (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - active_engines_only ? "ListActiveEngines" : "ListEngines", - NULL, - G_VARIANT_TYPE ("(av)")); + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + IBUS_INTERFACE_IBUS, + property), + G_VARIANT_TYPE ("(v)")); if (result) { + GVariant *variant = NULL; GVariantIter *iter = NULL; - g_variant_get (result, "(av)", &iter); + + g_variant_get (result, "(v)", &variant); + iter = g_variant_iter_new (variant); GVariant *var; while (g_variant_iter_loop (iter, "v", &var)) { IBusSerializable *serializable = ibus_serializable_deserialize (var); @@ -1546,6 +1563,7 @@ ibus_bus_do_list_engines (IBusBus *bus, gboolean active_engines_only) retval = g_list_append (retval, serializable); } g_variant_iter_free (iter); + g_variant_unref (variant); g_variant_unref (result); } @@ -1570,10 +1588,12 @@ ibus_bus_list_engines_async (IBusBus *bus, ibus_bus_call_async (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "ListEngines", - NULL, - G_VARIANT_TYPE ("(av)"), + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + IBUS_INTERFACE_IBUS, + "Engines"), + G_VARIANT_TYPE ("(v)"), ibus_bus_list_engines_async, timeout_msec, cancellable, @@ -1589,12 +1609,14 @@ ibus_bus_list_engines_async_finish (IBusBus *bus, GSimpleAsyncResult *simple = (GSimpleAsyncResult *) res; if (g_simple_async_result_propagate_error (simple, error)) return NULL; - GVariant *variant = g_simple_async_result_get_op_res_gpointer (simple); - g_return_val_if_fail (variant != NULL, NULL); + GVariant *result = g_simple_async_result_get_op_res_gpointer (simple); + g_return_val_if_fail (result != NULL, NULL); + GVariant *variant = NULL; GList *retval = NULL; GVariantIter *iter = NULL; - g_variant_get (variant, "(av)", &iter); + g_variant_get (result, "(v)", &variant); + iter = g_variant_iter_new (variant); GVariant *var; while (g_variant_iter_loop (iter, "v", &var)) { IBusSerializable *serializable = ibus_serializable_deserialize (var); @@ -1602,9 +1624,11 @@ ibus_bus_list_engines_async_finish (IBusBus *bus, retval = g_list_append (retval, serializable); } g_variant_iter_free (iter); + g_variant_unref (variant); return retval; } +#ifndef IBUS_DISABLE_DEPRECATED GList * ibus_bus_list_active_engines (IBusBus *bus) { @@ -1623,10 +1647,12 @@ ibus_bus_list_active_engines_async (IBusBus *bus, ibus_bus_call_async (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "ListActiveEngines", - NULL, - G_VARIANT_TYPE ("(av)"), + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + IBUS_INTERFACE_IBUS, + "ActiveEngines"), + G_VARIANT_TYPE ("(v)"), ibus_bus_list_active_engines_async, timeout_msec, cancellable, @@ -1641,6 +1667,7 @@ ibus_bus_list_active_engines_async_finish (IBusBus *bus, { return ibus_bus_list_engines_async_finish (bus, res, error); } +#endif /* IBUS_DISABLE_DEPRECATED */ IBusEngineDesc ** ibus_bus_get_engines_by_names (IBusBus *bus, @@ -1706,6 +1733,7 @@ ibus_bus_get_config (IBusBus *bus) return priv->config; } +#ifndef IBUS_DISABLE_DEPRECATED gboolean ibus_bus_get_use_sys_layout (IBusBus *bus) { @@ -1758,8 +1786,9 @@ ibus_bus_get_use_sys_layout_async_finish (IBusBus *bus, GError **error) { g_assert (IBUS_IS_BUS (bus)); - g_assert (g_simple_async_result_is_valid (res, (GObject *) bus, - ibus_bus_get_use_sys_layout_async)); + g_assert (g_simple_async_result_is_valid ( + res, (GObject *) bus, + ibus_bus_get_use_sys_layout_async)); return _async_finish_gboolean (res, error); } @@ -1815,8 +1844,9 @@ ibus_bus_get_use_global_engine_async_finish (IBusBus *bus, GError **error) { g_assert (IBUS_IS_BUS (bus)); - g_assert (g_simple_async_result_is_valid (res, (GObject *) bus, - ibus_bus_get_use_global_engine_async)); + g_assert (g_simple_async_result_is_valid ( + res, (GObject *) bus, + ibus_bus_get_use_global_engine_async)); return _async_finish_gboolean (res, error); } @@ -1870,10 +1900,12 @@ gboolean ibus_bus_is_global_engine_enabled_async_finish (IBusBus *bus, GError **error) { g_assert (IBUS_IS_BUS (bus)); - g_assert (g_simple_async_result_is_valid (res, (GObject *) bus, - ibus_bus_is_global_engine_enabled_async)); + g_assert (g_simple_async_result_is_valid ( + res, (GObject *) bus, + ibus_bus_is_global_engine_enabled_async)); return _async_finish_gboolean (res, error); } +#endif /* IBUS_DISABLE_DEPRECATED */ IBusEngineDesc * ibus_bus_get_global_engine (IBusBus *bus) @@ -1885,16 +1917,20 @@ ibus_bus_get_global_engine (IBusBus *bus) result = ibus_bus_call_sync (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "GetGlobalEngine", - NULL, + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + IBUS_INTERFACE_IBUS, + "GlobalEngine"), G_VARIANT_TYPE ("(v)")); if (result) { GVariant *variant = NULL; g_variant_get (result, "(v)", &variant); if (variant) { - engine = IBUS_ENGINE_DESC (ibus_serializable_deserialize (variant)); + GVariant *obj = g_variant_get_variant (variant); + engine = IBUS_ENGINE_DESC (ibus_serializable_deserialize (obj)); + g_variant_unref (obj); g_variant_unref (variant); } g_variant_unref (result); @@ -1915,9 +1951,11 @@ ibus_bus_get_global_engine_async (IBusBus *bus, ibus_bus_call_async (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "GetGlobalEngine", - NULL, + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + IBUS_INTERFACE_IBUS, + "GlobalEngine"), G_VARIANT_TYPE ("(v)"), ibus_bus_get_global_engine_async, timeout_msec, @@ -1934,15 +1972,17 @@ ibus_bus_get_global_engine_async_finish (IBusBus *bus, GSimpleAsyncResult *simple = (GSimpleAsyncResult *) res; if (g_simple_async_result_propagate_error (simple, error)) return NULL; - GVariant *variant = g_simple_async_result_get_op_res_gpointer (simple); - g_return_val_if_fail (variant != NULL, NULL); - GVariant *inner_variant = NULL; - g_variant_get (variant, "(v)", &inner_variant); + GVariant *result = g_simple_async_result_get_op_res_gpointer (simple); + g_return_val_if_fail (result != NULL, NULL); + GVariant *variant = NULL; + g_variant_get (result, "(v)", &variant); IBusEngineDesc *engine = NULL; - if (inner_variant) { - engine = IBUS_ENGINE_DESC (ibus_serializable_deserialize (inner_variant)); - g_variant_unref (inner_variant); + if (variant) { + GVariant *obj = g_variant_get_variant (variant); + engine = IBUS_ENGINE_DESC (ibus_serializable_deserialize (obj)); + g_variant_unref (obj); + g_variant_unref (variant); } return engine; } @@ -2011,16 +2051,21 @@ ibus_bus_preload_engines (IBusBus *bus, const gchar * const *names) { GVariant *result; + GVariant *variant = NULL; g_return_val_if_fail (IBUS_IS_BUS (bus), FALSE); g_return_val_if_fail (names != NULL && names[0] != NULL, FALSE); + variant = g_variant_new_strv(names, -1); result = ibus_bus_call_sync (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "PreloadEngines", - g_variant_new("(^as)", names), + "org.freedesktop.DBus.Properties", + "Set", + g_variant_new ("(ssv)", + IBUS_INTERFACE_IBUS, + "PreloadEngines", + variant), NULL); if (result) { @@ -2039,15 +2084,21 @@ ibus_bus_preload_engines_async (IBusBus *bus, GAsyncReadyCallback callback, gpointer user_data) { + GVariant *variant = NULL; + g_return_if_fail (IBUS_IS_BUS (bus)); g_return_if_fail (names != NULL && names[0] != NULL); + variant = g_variant_new_strv(names, -1); ibus_bus_call_async (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "PreloadEngines", - g_variant_new("(^as)", names), + "org.freedesktop.DBus.Properties", + "Set", + g_variant_new ("(ssv)", + IBUS_INTERFACE_IBUS, + "PreloadEngines", + variant), NULL, /* no return value */ ibus_bus_preload_engines_async, timeout_msec, @@ -2097,6 +2148,49 @@ ibus_bus_get_ibus_property (IBusBus *bus, } void +ibus_bus_get_ibus_property_async (IBusBus *bus, + const gchar *property_name, + gint timeout_msec, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_return_if_fail (IBUS_IS_BUS (bus)); + g_return_if_fail (property_name != NULL); + + ibus_bus_call_async (bus, + IBUS_SERVICE_IBUS, + IBUS_PATH_IBUS, + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + IBUS_INTERFACE_IBUS, + property_name), + G_VARIANT_TYPE ("(v)"), + ibus_bus_get_ibus_property_async, + timeout_msec, + cancellable, + callback, + user_data); +} + +GVariant * +ibus_bus_get_ibus_property_async_finish (IBusBus *bus, + GAsyncResult *res, + GError **error) +{ + GSimpleAsyncResult *simple = (GSimpleAsyncResult *) res; + if (g_simple_async_result_propagate_error (simple, error)) + return NULL; + GVariant *result = g_simple_async_result_get_op_res_gpointer (simple); + g_return_val_if_fail (result != NULL, NULL); + GVariant *retval = NULL; + g_variant_get (result, "(v)", &retval); + + return retval; +} + +void ibus_bus_set_ibus_property (IBusBus *bus, const gchar *property_name, GVariant *value) @@ -2122,6 +2216,47 @@ ibus_bus_set_ibus_property (IBusBus *bus, } } +void +ibus_bus_set_ibus_property_async (IBusBus *bus, + const gchar *property_name, + GVariant *value, + gint timeout_msec, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_return_if_fail (IBUS_IS_BUS (bus)); + g_return_if_fail (property_name != NULL); + + ibus_bus_call_async (bus, + IBUS_SERVICE_IBUS, + IBUS_PATH_IBUS, + "org.freedesktop.DBus.Properties", + "Set", + g_variant_new ("(ssv)", + IBUS_INTERFACE_IBUS, + property_name, + value), + NULL, /* no return value */ + ibus_bus_set_ibus_property_async, + timeout_msec, + cancellable, + callback, + user_data); +} + +gboolean +ibus_bus_set_ibus_property_async_finish (IBusBus *bus, + GAsyncResult *res, + GError **error) +{ + g_assert (IBUS_IS_BUS (bus)); + g_assert (g_simple_async_result_is_valid ( + res, (GObject *) bus, + ibus_bus_set_ibus_property_async)); + return _async_finish_void (res, error); +} + static GVariant * ibus_bus_call_sync (IBusBus *bus, const gchar *bus_name, diff --git a/src/ibusbus.h b/src/ibusbus.h index 6344337c..4e25a9a3 100644 --- a/src/ibusbus.h +++ b/src/ibusbus.h @@ -1,8 +1,8 @@ /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ /* vim:set et sts=4: */ /* ibus - The Input Bus - * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com> - * Copyright (C) 2008-2010 Red Hat, Inc. + * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com> + * Copyright (C) 2008-2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -35,9 +35,11 @@ * An IBusBus connects with IBus daemon. */ #include <gio/gio.h> +#include <glib.h> #include "ibusinputcontext.h" #include "ibusconfig.h" #include "ibuscomponent.h" +#include "ibusshare.h" /* * Type macros. @@ -676,13 +678,18 @@ GList *ibus_bus_list_engines_async_finish GAsyncResult *res, GError **error); +#ifndef IBUS_DISABLE_DEPRECATED /** * ibus_bus_list_active_engines: * @bus: An #IBusBus. * @returns: (transfer container) (element-type IBusEngineDesc): A List of active engines. * * List active engines synchronously. + * + * Deprecated: 1.5.3: Read dconf value + * /desktop/ibus/general/preload-engines instead. */ +IBUS_DEPRECATED GList *ibus_bus_list_active_engines (IBusBus *bus); @@ -696,7 +703,11 @@ GList *ibus_bus_list_active_engines * @user_data: The data to pass to callback. * * List active engines asynchronously. + * + * Deprecated: 1.5.3: Read dconf value + * /desktop/ibus/general/preload-engines instead. */ +IBUS_DEPRECATED void ibus_bus_list_active_engines_async (IBusBus *bus, gint timeout_msec, @@ -714,11 +725,16 @@ void ibus_bus_list_active_engines_async * @returns: (transfer container) (element-type IBusEngineDesc): A List of active engines. * * Finishes an operation started with ibus_bus_list_active_engines_async(). + * + * Deprecated: 1.5.3: Read dconf value + * /desktop/ibus/general/preload-engines instead. */ +IBUS_DEPRECATED GList *ibus_bus_list_active_engines_async_finish (IBusBus *bus, GAsyncResult *res, GError **error); +#endif /* IBUS_DISABLE_DEPRECATED */ /** * ibus_bus_get_engines_by_names: @@ -734,13 +750,18 @@ IBusEngineDesc ** ibus_bus_get_engines_by_names (IBusBus *bus, const gchar * const *names); +#ifndef IBUS_DISABLE_DEPRECATED /** * ibus_bus_get_use_sys_layout: * @bus: An #IBusBus. * @returns: %TRUE if "use_sys_layout" option is enabled. * * Check if the bus's "use_sys_layout" option is enabled or not synchronously. + * + * Deprecated: 1.5.3: Read dconf value + * /desktop/ibus/general/use_system_keyboard_layout instead. */ +IBUS_DEPRECATED gboolean ibus_bus_get_use_sys_layout (IBusBus *bus); @@ -754,7 +775,11 @@ gboolean ibus_bus_get_use_sys_layout * @user_data: The data to pass to callback. * * Check if the bus's "use_sys_layout" option is enabled or not asynchronously. + * + * Deprecated: 1.5.3: Read dconf value + * /desktop/ibus/general/use_system_keyboard_layout instead. */ +IBUS_DEPRECATED void ibus_bus_get_use_sys_layout_async (IBusBus *bus, gint timeout_msec, @@ -772,7 +797,11 @@ void ibus_bus_get_use_sys_layout_async * @returns: TRUE if "use_sys_layout" option is enabled. * * Finishes an operation started with ibus_bus_get_use_sys_layout_async(). + * + * Deprecated: 1.5.3: Read dconf value + * /desktop/ibus/general/use_system_keyboard_layout instead. */ +IBUS_DEPRECATED gboolean ibus_bus_get_use_sys_layout_async_finish (IBusBus *bus, GAsyncResult *res, @@ -784,7 +813,10 @@ gboolean ibus_bus_get_use_sys_layout_async_finish * @returns: TRUE if "use_global_engine" option is enabled. * * Check if the bus's "use_global_engine" option is enabled or not synchronously. + * + * Deprecated: 1.5.3: Currently global engine is always used. */ +IBUS_DEPRECATED gboolean ibus_bus_get_use_global_engine (IBusBus *bus); @@ -798,7 +830,10 @@ gboolean ibus_bus_get_use_global_engine * @user_data: The data to pass to callback. * * Check if the bus's "use_global_engine" option is enabled or not asynchronously. + * + * Deprecated: 1.5.3: Currently global engine is always used. */ +IBUS_DEPRECATED void ibus_bus_get_use_global_engine_async (IBusBus *bus, gint timeout_msec, @@ -816,7 +851,10 @@ void ibus_bus_get_use_global_engine_async * @returns: %TRUE if "use_global_engine" option is enabled. * * Finishes an operation started with ibus_bus_get_use_global_engine_async(). + * + * Deprecated: 1.5.3: Currently global engine is always used. */ +IBUS_DEPRECATED gboolean ibus_bus_get_use_global_engine_async_finish (IBusBus *bus, GAsyncResult *res, @@ -828,7 +866,14 @@ gboolean ibus_bus_get_use_global_engine_async_finish * @returns: %TRUE if the current global engine is enabled. * * Check if the current global engine is enabled or not synchronously. + * + * Deprecated: 1.5.3: Probably this would be used for Chrome OS only. + * Currently global engine is always used and ibus_bus_get_global_engine() + * returns NULL until the first global engine is assigned. + * You can use ibus_set_log_handler() to disable a warning when + * ibus_bus_get_global_engine() returns NULL. */ +IBUS_DEPRECATED gboolean ibus_bus_is_global_engine_enabled (IBusBus *bus); @@ -842,7 +887,14 @@ gboolean ibus_bus_is_global_engine_enabled * @user_data: The data to pass to callback. * * Check if the current global engine is enabled or not asynchronously. + * + * Deprecated: 1.5.3: Probably this would be used for Chrome OS only. + * Currently global engine is always used and ibus_bus_get_global_engine() + * returns NULL until the first global engine is assigned. + * You can use ibus_set_log_handler() to disable a warning when + * ibus_bus_get_global_engine() returns NULL. */ +IBUS_DEPRECATED void ibus_bus_is_global_engine_enabled_async (IBusBus *bus, gint timeout_msec, @@ -860,11 +912,19 @@ void ibus_bus_is_global_engine_enabled_async * @returns: %TRUE if the current global engine is enabled. * * Finishes an operation started with ibus_bus_is_global_engine_enabled_async(). + * + * Deprecated: 1.5.3: Probably this would be used for Chrome OS only. + * Currently global engine is always used and ibus_bus_get_global_engine() + * returns NULL until the first global engine is assigned. + * You can use ibus_set_log_handler() to disable a warning when + * ibus_bus_get_global_engine() returns NULL. */ +IBUS_DEPRECATED gboolean ibus_bus_is_global_engine_enabled_async_finish (IBusBus *bus, GAsyncResult *res, GError **error); +#endif /* IBUS_DISABLE_DEPRECATED */ /** * ibus_bus_get_global_engine: @@ -1056,6 +1116,43 @@ GVariant * ibus_bus_get_ibus_property (IBusBus *bus, const gchar *property_name); /** + * ibus_bus_get_ibus_property_async: + * @bus: An #IBusBus. + * @property_name: property name in org.freedesktop.DBus.Properties.Get + * @timeout_msec: The timeout in milliseconds or -1 to use the default timeout. + * @cancellable: A #GCancellable or %NULL. + * @callback: A #GAsyncReadyCallback to call when the request is satisfied + * or %NULL if you don't care about the result of the method invocation. + * @user_data: The data to pass to callback. + * + * Get org.freedesktop.DBus.Properties asynchronously. + */ +void ibus_bus_get_ibus_property_async + (IBusBus *bus, + const gchar *property_name, + gint timeout_msec, + GCancellable *cancellable, + GAsyncReadyCallback + callback, + gpointer user_data); + +/** + * ibus_bus_get_ibus_property_async_finish: + * @bus: An #IBusBus. + * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to + * ibus_bus_get_property_async(). + * @error: Return location for error or %NULL. + * @returns: (transfer full): The value in org.freedesktop.DBus.Properties.Get + * The returned value must be freed with g_variant_unref(). + * + * Finishes an operation started with ibus_bus_get_ibus_property_async(). + */ +GVariant * ibus_bus_get_ibus_property_async_finish + (IBusBus *bus, + GAsyncResult *res, + GError **error); + +/** * ibus_bus_set_ibus_property: * @bus: An #IBusBus. * @property_name: property name in org.freedesktop.DBus.Properties.Set @@ -1067,5 +1164,43 @@ void ibus_bus_set_ibus_property (IBusBus *bus, const gchar *property_name, GVariant *value); +/** + * ibus_bus_set_ibus_property_async: + * @bus: An #IBusBus. + * @property_name: property name in org.freedesktop.DBus.Properties.Set + * @value: value in org.freedesktop.DBus.Properties.Set + * @timeout_msec: The timeout in milliseconds or -1 to use the default timeout. + * @cancellable: A #GCancellable or %NULL. + * @callback: A #GAsyncReadyCallback to call when the request is satisfied + * or %NULL if you don't care about the result of the method invocation. + * @user_data: The data to pass to callback. + * + * Set org.freedesktop.DBus.Properties asynchronously. + */ +void ibus_bus_set_ibus_property_async + (IBusBus *bus, + const gchar *property_name, + GVariant *value, + gint timeout_msec, + GCancellable *cancellable, + GAsyncReadyCallback + callback, + gpointer user_data); + +/** + * ibus_bus_set_ibus_property_async_finish: + * @bus: An #IBusBus. + * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to + * ibus_bus_set_property_async(). + * @error: Return location for error or %NULL. + * @returns: %TRUE if property is set with async. %FALSE failed. + * + * Finishes an operation started with ibus_bus_set_ibus_property_async(). + */ +gboolean ibus_bus_set_ibus_property_async_finish + (IBusBus *bus, + GAsyncResult *res, + GError **error); + G_END_DECLS #endif diff --git a/src/ibusshare.h b/src/ibusshare.h index 512fa599..5fc135db 100644 --- a/src/ibusshare.h +++ b/src/ibusshare.h @@ -38,6 +38,12 @@ #include <glib.h> +#ifdef IBUS_DISABLE_DEPRECATION_WARNINGS +#define IBUS_DEPRECATED +#else +#define IBUS_DEPRECATED G_DEPRECATED +#endif + /** * IBUS_SERVICE_IBUS: * diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index bf7c6a9e..ad8bb8e5 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -24,12 +24,13 @@ NULL = DEPS = $(top_builddir)/src/libibus-@IBUS_API_VERSION@.la -AM_CPPFLAGS = \ - -g \ - @GLIB2_CFLAGS@ \ - @GIO2_CFLAGS@ \ - -I$(top_srcdir)/src \ - -I$(top_builddir)/src \ +AM_CPPFLAGS = \ + -g \ + @GLIB2_CFLAGS@ \ + @GIO2_CFLAGS@ \ + -DIBUS_DISABLE_DEPRECATION_WARNINGS \ + -I$(top_srcdir)/src \ + -I$(top_builddir)/src \ $(NULL) prog_ldadd = \ diff --git a/src/tests/ibus-bus.c b/src/tests/ibus-bus.c index f3f93bdf..e370eb29 100644 --- a/src/tests/ibus-bus.c +++ b/src/tests/ibus-bus.c @@ -20,6 +20,7 @@ print_engines (const GList *engines) } } +#ifndef IBUS_DISABLE_DEPRECATED static void test_list_active_engines (void) { @@ -32,6 +33,7 @@ test_list_active_engines (void) g_list_foreach (engines, (GFunc) g_object_unref, NULL); g_list_free (engines); } +#endif /* IBUS_DISABLE_DEPRECATED */ static void test_list_engines (void) @@ -353,6 +355,7 @@ start_list_engines_async (void) NULL); /* user_data */ } +#ifndef IBUS_DISABLE_DEPRECATED static void finish_list_active_engines_async (GObject *source_object, GAsyncResult *res, @@ -447,6 +450,7 @@ start_is_global_engine_enabled_async (void) finish_is_global_engine_enabled_async, NULL); /* user_data */ } +#endif /* IBUS_DISABLE_DEPRECATED */ static void finish_get_global_engine_async (GObject *source_object, @@ -523,6 +527,233 @@ start_preload_engines_async (void) } static void +test_get_address (void) +{ + GVariant *result; + + result = ibus_bus_get_ibus_property (bus, "Address"); + g_variant_get_string (result, NULL); + g_variant_unref (result); +} + +static void +test_get_current_input_context (void) +{ + GVariant *result; + + result = ibus_bus_get_ibus_property (bus, "CurrentInputContext"); + g_variant_get_string (result, NULL); + g_variant_unref (result); +} + +static void +test_get_engines (void) +{ + GVariant *result, *var; + GVariantIter *iter; + GList *engines = NULL; + + result = ibus_bus_get_ibus_property (bus, "Engines"); + iter = g_variant_iter_new (result); + while (g_variant_iter_loop (iter, "v", &var)) { + IBusSerializable *serializable = ibus_serializable_deserialize (var); + g_object_ref_sink (serializable); + engines = g_list_append (engines, serializable); + } + g_variant_iter_free (iter); + g_variant_unref (result); + + print_engines (engines); + + g_list_foreach (engines, (GFunc) g_object_unref, NULL); + g_list_free (engines); +} + +static void +test_get_global_engine (void) +{ + GVariant *result, *obj; + IBusEngineDesc *desc = NULL; + + result = ibus_bus_get_ibus_property (bus, "GlobalEngine"); + obj = g_variant_get_variant (result); + desc = IBUS_ENGINE_DESC (ibus_serializable_deserialize (obj)); + g_variant_unref (obj); + g_variant_unref (result); + + if (desc) + g_object_unref (desc); +} + +static void +test_set_preload_engines (void) +{ + const gchar *preload_engines[] = { "xkb:us::eng", "xkb:jp::jpn", NULL }; + GVariant *variant; + + variant = g_variant_new_strv (preload_engines, -1); + ibus_bus_set_ibus_property (bus, "PreloadEngines", variant); +} + +static void +finish_get_address_async (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + GVariant *result; + + result = ibus_bus_get_ibus_property_async_finish (bus, res, &error); + g_variant_get_string (result, NULL); + g_variant_unref (result); + g_debug ("finish_get_address_async: OK"); + call_next_async_function (); +} + +static void +start_get_address_async (void) +{ + ibus_bus_get_ibus_property_async ( + bus, + "Address", + -1, /* timeout */ + NULL, /* cancellable */ + finish_get_address_async, + NULL); /* user_data */ +} + +static void +finish_get_current_input_context_async (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + GVariant *result; + + result = ibus_bus_get_ibus_property_async_finish (bus, res, &error); + g_variant_get_string (result, NULL); + g_variant_unref (result); + g_debug ("finish_get_current_input_context_async: OK"); + call_next_async_function (); +} + +static void +start_get_current_input_context_async (void) +{ + ibus_bus_get_ibus_property_async ( + bus, + "CurrentInputContext", + -1, /* timeout */ + NULL, /* cancellable */ + finish_get_current_input_context_async, + NULL); /* user_data */ +} + +static void +finish_get_engines_async (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + GVariant *result, *var; + GVariantIter *iter; + GList *engines = NULL; + + result = ibus_bus_get_ibus_property_async_finish (bus, res, &error); + iter = g_variant_iter_new (result); + while (g_variant_iter_loop (iter, "v", &var)) { + IBusSerializable *serializable = ibus_serializable_deserialize (var); + g_object_ref_sink (serializable); + engines = g_list_append (engines, serializable); + } + g_variant_iter_free (iter); + g_variant_unref (result); + + print_engines (engines); + + g_list_foreach (engines, (GFunc) g_object_unref, NULL); + g_list_free (engines); + + g_debug ("finish_get_engines_async: OK"); + call_next_async_function (); +} + +static void +start_get_engines_async (void) +{ + ibus_bus_get_ibus_property_async ( + bus, + "Engines", + -1, /* timeout */ + NULL, /* cancellable */ + finish_get_engines_async, + NULL); /* user_data */ +} + +static void +finish_get_prop_global_engine_async (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + GVariant *result, *obj; + IBusEngineDesc *desc = NULL; + + result = ibus_bus_get_ibus_property_async_finish (bus, res, &error); + obj = g_variant_get_variant (result); + desc = IBUS_ENGINE_DESC (ibus_serializable_deserialize (obj)); + g_variant_unref (obj); + g_variant_unref (result); + + if (desc) + g_object_unref (desc); + + g_debug ("finish_get_prop_global_engine_async: OK"); + call_next_async_function (); +} + +static void +start_get_prop_global_engine_async (void) +{ + ibus_bus_get_ibus_property_async ( + bus, + "GlobalEngine", + -1, /* timeout */ + NULL, /* cancellable */ + finish_get_prop_global_engine_async, + NULL); /* user_data */ +} + +static void +finish_set_preload_engines_async (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + + ibus_bus_set_ibus_property_async_finish (bus, res, &error); + g_debug ("finish_set_preload_engines_async: OK"); + call_next_async_function (); +} + +static void +start_set_preload_engines_async (void) +{ + const gchar *preload_engines[] = { "xkb:us::eng", "xkb:jp::jpn", NULL }; + GVariant *variant; + + variant = g_variant_new_strv (preload_engines, -1); + ibus_bus_set_ibus_property_async ( + bus, + "PreloadEngines", + variant, + -1, /* timeout */ + NULL, /* cancellable */ + finish_set_preload_engines_async, + NULL); /* user_data */ +} + +static void finish_exit_async (GObject *source_object, GAsyncResult *res, gpointer user_data) @@ -619,6 +850,11 @@ call_next_async_function (void) start_set_global_engine_async, start_get_global_engine_async, start_preload_engines_async, + start_get_address_async, + start_get_current_input_context_async, + start_get_engines_async, + start_get_prop_global_engine_async, + start_set_preload_engines_async, start_exit_async, }; static guint index = 0; @@ -663,6 +899,12 @@ main (gint argc, g_test_add_func ("/ibus/create-input-context-async", test_create_input_context_async); g_test_add_func ("/ibus/get-engines-by-names", test_get_engines_by_names); + g_test_add_func ("/ibus/get-address", test_get_address); + g_test_add_func ("/ibus/get-current-input-context", + test_get_current_input_context); + g_test_add_func ("/ibus/get-engines", test_get_engines); + g_test_add_func ("/ibus/get-global-engine", test_get_global_engine); + g_test_add_func ("/ibus/set-preload-engines", test_set_preload_engines); g_test_add_func ("/ibus/async-apis", test_async_apis); g_test_add_func ("/ibus/bus-new-async", test_bus_new_async); g_test_add_func ("/ibus/bus-new-async/list-engines", test_list_engines); |