Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(250)

Side by Side Diff: src/ibusinputcontext.c

Issue 4275048: Add asynchronous InputContext.IsEnabled and InputContext.GetEngine APIs. (Closed) Base URL: git@github.com:ibus/ibus.git@master
Patch Set: review Created 3 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ 1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2 /* vim:set et sts=4: */ 2 /* vim:set et sts=4: */
3 /* ibus - The Input Bus 3 /* ibus - The Input Bus
4 * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com> 4 * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
5 * Copyright (C) 2008-2010 Red Hat, Inc. 5 * Copyright (C) 2008-2010 Red Hat, Inc.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 637
638 IBusInputContext * 638 IBusInputContext *
639 ibus_input_context_get_input_context (const gchar *path, 639 ibus_input_context_get_input_context (const gchar *path,
640 GDBusConnection *connection) 640 GDBusConnection *connection)
641 { 641 {
642 IBusInputContext *context; 642 IBusInputContext *context;
643 GError *error = NULL; 643 GError *error = NULL;
644 644
645 context = ibus_input_context_new (path, connection, NULL, &error); 645 context = ibus_input_context_new (path, connection, NULL, &error);
646 if (!context) { 646 if (!context) {
647 g_warning ("%s", error->message); 647 if (error != NULL && error->message != NULL) {
Peng 2011/03/14 13:40:46 Is it necessary?
Yusuke Sato 2011/03/18 14:08:01 I think GDBus functions sometimes return 'fail' wi
Peng 2011/03/18 15:30:33 IMHO, error must be set, if function call is faile
Yusuke Sato 2011/03/21 05:13:32 OK, I'm convinced. I'll remove the redundant check
648 g_warning ("ibus_input_context_get_input_context: %s", error->messag e);
649 }
648 g_error_free (error); 650 g_error_free (error);
649 return NULL; 651 return NULL;
650 } 652 }
651 653
652 /* Do not call "org.freedesktop.IBus.Service.Destroy" when the input 654 /* Do not call "org.freedesktop.IBus.Service.Destroy" when the input
653 * context object is disposed. */ 655 * context object is disposed. */
654 IBUS_PROXY (context)->own = FALSE; 656 IBUS_PROXY (context)->own = FALSE;
655 return context; 657 return context;
656 } 658 }
657 659
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 return FALSE; 700 return FALSE;
699 } 701 }
700 else { 702 else {
701 *processed = FALSE; 703 *processed = FALSE;
702 g_variant_get (variant, "(b)", processed); 704 g_variant_get (variant, "(b)", processed);
703 g_variant_unref (variant); 705 g_variant_unref (variant);
704 return TRUE; 706 return TRUE;
705 } 707 }
706 } 708 }
707 709
708
709 gboolean 710 gboolean
710 ibus_input_context_process_key_event (IBusInputContext *context, 711 ibus_input_context_process_key_event (IBusInputContext *context,
711 guint32 keyval, 712 guint32 keyval,
712 guint32 keycode, 713 guint32 keycode,
713 guint32 state) 714 guint32 state)
714 { 715 {
715 g_assert (IBUS_IS_INPUT_CONTEXT (context)); 716 g_assert (IBUS_IS_INPUT_CONTEXT (context));
716 717
717 GVariant *result = g_dbus_proxy_call_sync ((GDBusProxy *) context, 718 GVariant *result = g_dbus_proxy_call_sync ((GDBusProxy *) context,
718 "ProcessKeyEvent", /* method_name */ 719 "ProcessKeyEvent", /* method_name */
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 "PropertyHide", /* method_name */ 814 "PropertyHide", /* method_name */
814 g_variant_new ("(s)", prop_name), /* parameters */ 815 g_variant_new ("(s)", prop_name), /* parameters */
815 G_DBUS_CALL_FLAGS_NONE, /* flags */ 816 G_DBUS_CALL_FLAGS_NONE, /* flags */
816 -1, /* timeout */ 817 -1, /* timeout */
817 NULL, /* cancellable */ 818 NULL, /* cancellable */
818 NULL, /* callback */ 819 NULL, /* callback */
819 NULL /* user_data */ 820 NULL /* user_data */
820 ); 821 );
821 } 822 }
822 823
824 void
825 ibus_input_context_is_enabled_async (IBusInputContext *context,
826 gint timeout_msec,
827 GCancellable *cancellable,
828 GAsyncReadyCallback callback,
829 gpointer user_data)
830 {
831 g_assert (IBUS_IS_INPUT_CONTEXT (context));
832 g_dbus_proxy_call ((GDBusProxy *) context,
833 "IsEnabled", /* method_name */
834 NULL, /* parameters */
835 G_DBUS_CALL_FLAGS_NONE, /* flags */
836 timeout_msec,
837 cancellable,
838 callback,
839 user_data);
840 }
841
842 gboolean
843 ibus_input_context_is_enabled_async_finish (IBusInputContext *context,
844 GAsyncResult *res,
845 GError **error)
Peng 2011/03/14 13:40:46 The return type is boolean value. I think the call
Yusuke Sato 2011/03/18 14:08:01 Sounds reasonable to me. Fixed the signature of ib
Peng 2011/03/18 15:30:33 Yeah. Some functions return gint. It is difficult
Yusuke Sato 2011/03/21 05:13:32 ok, I'll file a bug on code.google.com/p/ibus. O
846 {
847 g_assert (IBUS_IS_INPUT_CONTEXT (context));
848 g_assert (G_IS_ASYNC_RESULT (res));
849 g_assert (error == NULL || *error == NULL);
850
851 GVariant *variant = g_dbus_proxy_call_finish ((GDBusProxy *) context,
852 res, error);
853 if (variant == NULL) {
854 return FALSE;
855 }
856 gboolean result = FALSE;
857 g_variant_get (variant, "(b)", &result);
858 g_variant_unref (variant);
859 return result;
860 }
861
823 gboolean 862 gboolean
824 ibus_input_context_is_enabled (IBusInputContext *context) 863 ibus_input_context_is_enabled (IBusInputContext *context)
825 { 864 {
826 g_assert (IBUS_IS_INPUT_CONTEXT (context)); 865 g_assert (IBUS_IS_INPUT_CONTEXT (context));
827 GVariant *result; 866 GVariant *result;
828 GError *error = NULL; 867 GError *error = NULL;
829 result = g_dbus_proxy_call_sync ((GDBusProxy *) context, 868 result = g_dbus_proxy_call_sync ((GDBusProxy *) context,
830 "IsEnabled", /* method_name * / 869 "IsEnabled", /* method_name * /
831 NULL, /* parameters */ 870 NULL, /* parameters */
832 G_DBUS_CALL_FLAGS_NONE, /* flags */ 871 G_DBUS_CALL_FLAGS_NONE, /* flags */
833 -1, /* timeout */ 872 -1, /* timeout */
834 NULL, /* cancellable * / 873 NULL, /* cancellable * /
835 &error /* error */ 874 &error /* error */
836 ); 875 );
837 876
838 if (result == NULL) { 877 if (result == NULL) {
839 g_warning ("%s.IsEnabled: %s", IBUS_INTERFACE_INPUT_CONTEXT, error->mess age); 878 if (error != NULL && error->message != NULL) {
Peng 2011/03/14 13:40:46 Is it necessary?
Yusuke Sato 2011/03/18 14:08:01 ditto.
879 g_warning ("%s.IsEnabled: %s", IBUS_INTERFACE_INPUT_CONTEXT, error-> message);
880 }
840 g_error_free (error); 881 g_error_free (error);
841 return FALSE; 882 return FALSE;
842 } 883 }
843 884
844 gboolean retval = FALSE; 885 gboolean retval = FALSE;
845 g_variant_get (result, "(b)", &retval); 886 g_variant_get (result, "(b)", &retval);
846 g_variant_unref (result); 887 g_variant_unref (result);
847 888
848 return retval; 889 return retval;
849 } 890 }
850 891
892 void
893 ibus_input_context_get_engine_async (IBusInputContext *context,
894 gint timeout_msec,
895 GCancellable *cancellable,
896 GAsyncReadyCallback callback,
897 gpointer user_data)
898 {
899 g_assert (IBUS_IS_INPUT_CONTEXT (context));
900 g_dbus_proxy_call ((GDBusProxy *) context,
901 "GetEngine", /* method_name */
902 NULL, /* parameters */
903 G_DBUS_CALL_FLAGS_NONE, /* flags */
904 timeout_msec,
905 cancellable,
906 callback,
907 user_data);
908 }
909
910 IBusEngineDesc *
911 ibus_input_context_get_engine_async_finish (IBusInputContext *context,
912 GAsyncResult *res,
913 GError **error)
914 {
915 g_assert (IBUS_IS_INPUT_CONTEXT (context));
916 g_assert (G_IS_ASYNC_RESULT (res));
917 g_assert (error == NULL || *error == NULL);
918
919 GVariant *variant = g_dbus_proxy_call_finish ((GDBusProxy *) context,
920 res, error);
921 if (variant == NULL) {
922 return NULL;
923 }
924
925 GVariant *engine_desc_variant = g_variant_get_child_value (variant, 0);
926 IBusEngineDesc *desc = IBUS_ENGINE_DESC (ibus_serializable_deserialize (engi ne_desc_variant));
927 g_variant_unref (engine_desc_variant);
928 g_variant_unref (variant);
929
930 return desc;
931 }
932
851 IBusEngineDesc * 933 IBusEngineDesc *
852 ibus_input_context_get_engine (IBusInputContext *context) 934 ibus_input_context_get_engine (IBusInputContext *context)
853 { 935 {
854 g_assert (IBUS_IS_INPUT_CONTEXT (context)); 936 g_assert (IBUS_IS_INPUT_CONTEXT (context));
855 GVariant *result; 937 GVariant *result;
856 GError *error = NULL; 938 GError *error = NULL;
857 result = g_dbus_proxy_call_sync ((GDBusProxy *) context, 939 result = g_dbus_proxy_call_sync ((GDBusProxy *) context,
858 "GetEngine", /* method_name * / 940 "GetEngine", /* method_name * /
859 NULL, /* parameters */ 941 NULL, /* parameters */
860 G_DBUS_CALL_FLAGS_NONE, /* flags */ 942 G_DBUS_CALL_FLAGS_NONE, /* flags */
861 -1, /* timeout */ 943 -1, /* timeout */
862 NULL, /* cancellable * / 944 NULL, /* cancellable * /
863 &error /* error */ 945 &error /* error */
864 ); 946 );
865 947
866 if (result == NULL) { 948 if (result == NULL) {
867 g_warning ("%s.GetEngine: %s", IBUS_INTERFACE_INPUT_CONTEXT, error->mess age); 949 if (error != NULL && error->message != NULL) {
Peng 2011/03/14 13:40:46 Is it necessary?
Yusuke Sato 2011/03/18 14:08:01 ditto.
950 g_warning ("%s.GetEngine: %s", IBUS_INTERFACE_INPUT_CONTEXT, error-> message);
951 }
868 g_error_free (error); 952 g_error_free (error);
869 return NULL; 953 return NULL;
870 } 954 }
871 955
872 GVariant *variant = g_variant_get_child_value (result, 0); 956 GVariant *engine_desc_variant = g_variant_get_child_value (result, 0);
873 IBusEngineDesc *desc = IBUS_ENGINE_DESC (ibus_serializable_deserialize (vari ant)); 957 IBusEngineDesc *desc = IBUS_ENGINE_DESC (ibus_serializable_deserialize (engi ne_desc_variant));
874 g_variant_unref (variant); 958 g_variant_unref (engine_desc_variant);
875 g_variant_unref (result); 959 g_variant_unref (result);
876 960
877 return desc; 961 return desc;
878 } 962 }
879 963
880 void 964 void
881 ibus_input_context_set_engine (IBusInputContext *context, 965 ibus_input_context_set_engine (IBusInputContext *context,
882 const gchar *name) 966 const gchar *name)
883 { 967 {
884 g_assert (IBUS_IS_INPUT_CONTEXT (context)); 968 g_assert (IBUS_IS_INPUT_CONTEXT (context));
(...skipping 29 matching lines...) Expand all
914 DEFINE_FUNC(focus_out, FocusOut); 998 DEFINE_FUNC(focus_out, FocusOut);
915 DEFINE_FUNC(reset, Reset); 999 DEFINE_FUNC(reset, Reset);
916 DEFINE_FUNC(page_up, PageUp); 1000 DEFINE_FUNC(page_up, PageUp);
917 DEFINE_FUNC(page_down, PageDown); 1001 DEFINE_FUNC(page_down, PageDown);
918 DEFINE_FUNC(cursor_up, CursorUp); 1002 DEFINE_FUNC(cursor_up, CursorUp);
919 DEFINE_FUNC(cursor_down, CursorDown); 1003 DEFINE_FUNC(cursor_down, CursorDown);
920 DEFINE_FUNC(enable, Enable); 1004 DEFINE_FUNC(enable, Enable);
921 DEFINE_FUNC(disable, Disable); 1005 DEFINE_FUNC(disable, Disable);
922 #undef DEFINE_FUNC 1006 #undef DEFINE_FUNC
923 1007
OLDNEW
« no previous file with comments | « src/ibusinputcontext.h ('k') | src/tests/Makefile.am » ('j') | src/tests/ibus-inputcontext.c » ('J')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1278:e6ce13d99bf5