Add IBUS_ERROR domain and reply IBUS_ERROR_NO_ENGINE in org.freedesktop.IBus.InputCon...
authorPeng Huang <shawn.p.huang@gmail.com>
Wed, 15 Jun 2011 14:38:17 +0000 (10:38 -0400)
committerPeng Huang <shawn.p.huang@gmail.com>
Wed, 15 Jun 2011 14:38:17 +0000 (10:38 -0400)
BUG=None
TEST=Manually

Review URL: http://codereview.appspot.com/4528140

bus/inputcontext.c
src/Makefile.am
src/ibus.h
src/ibuserror.c [new file with mode: 0644]
src/ibuserror.h [new file with mode: 0644]
src/ibusinputcontext.c
src/ibusshare.c
src/ibustypes.h
src/tests/ibus-gi-inputcontext.py [new file with mode: 0755]

index bad90ec..1567c5f 100644 (file)
@@ -1040,8 +1040,11 @@ _ic_get_engine (BusInputContext       *context,
                         g_variant_new ("(v)", ibus_serializable_serialize ((IBusSerializable *)desc)));
     }
     else {
-        g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
-                        "Input context does not have engine.");
+        g_dbus_method_invocation_return_error (
+                invocation,
+                IBUS_ERROR,
+                IBUS_ERROR_NO_ENGINE,
+                "Input context does not have engine.");
     }
 }
 
index 632fc72..a53bd23 100644 (file)
@@ -70,6 +70,7 @@ ibus_sources =              \
     ibusservice.c           \
     ibusfactory.c           \
     ibusengine.c            \
+    ibuserror.c                                \
     ibustext.c              \
     ibuskeymap.c            \
     ibusattribute.c         \
@@ -114,6 +115,7 @@ ibus_headers =              \
     ibusservice.h           \
     ibusfactory.h           \
     ibusengine.h            \
+    ibuserror.h                                \
     ibustext.h              \
     ibuskeymap.h            \
     ibusattribute.h         \
index 8df7160..c408f3d 100644 (file)
@@ -35,6 +35,7 @@
 #include <ibusservice.h>
 #include <ibusfactory.h>
 #include <ibusengine.h>
+#include <ibuserror.h>
 #include <ibusproperty.h>
 #include <ibusproplist.h>
 #include <ibuslookuptable.h>
diff --git a/src/ibuserror.c b/src/ibuserror.c
new file mode 100644 (file)
index 0000000..c50c164
--- /dev/null
@@ -0,0 +1,41 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/* vim:set et sts=4: */
+/* ibus - The Input Bus
+ * Copyright (C) 2011 Peng Huang <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "ibuserror.h"
+
+#include <gio/gio.h>
+#include "ibustypes.h"
+
+static const GDBusErrorEntry ibus_error_entries[] =
+{
+    { IBUS_ERROR_NO_ENGINE,         "org.freedesktop.IBus.Error.NoEngine" },
+};
+
+GQuark
+ibus_error_quark (void)
+{
+    static volatile gsize quark_volatile = 0;
+    g_dbus_error_register_error_domain ("ibus-error-quark",
+                                        &quark_volatile,
+                                        ibus_error_entries,
+                                        G_N_ELEMENTS (ibus_error_entries));
+    return (GQuark) quark_volatile;
+}
diff --git a/src/ibuserror.h b/src/ibuserror.h
new file mode 100644 (file)
index 0000000..75c64b9
--- /dev/null
@@ -0,0 +1,46 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/* vim:set et sts=4: */
+/* ibus - The Input Bus
+ * Copyright (C) 2011 Peng Huang <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if !defined (__IBUS_H_INSIDE__) && !defined (IBUS_COMPILATION)
+#error "Only <ibus.h> can be included directly"
+#endif
+
+/**
+ * SECTION: ibusshare
+ * @short_description: Shared utility functions and definition.
+ * @stability: Stable
+ *
+ * This file defines some utility functions and definition
+ * which are shared among ibus component and services.
+ */
+
+#ifndef __IBUS_ERROR_H_
+#define __IBUS_ERROR_H_
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#define IBUS_ERROR ibus_error_quark()
+GQuark ibus_error_quark (void);
+
+G_END_DECLS
+#endif
index e6f97e8..78d454e 100644 (file)
@@ -27,6 +27,7 @@
 #include "ibusattribute.h"
 #include "ibuslookuptable.h"
 #include "ibusproplist.h"
+#include "ibuserror.h"
 
 #define IBUS_INPUT_CONTEXT_GET_PRIVATE(o)  \
    (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_INPUT_CONTEXT, IBusInputContextPrivate))
@@ -1164,7 +1165,7 @@ IBusEngineDesc *
 ibus_input_context_get_engine (IBusInputContext *context)
 {
     g_assert (IBUS_IS_INPUT_CONTEXT (context));
-    GVariant *result;
+    GVariant *result = NULL;
     GError *error = NULL;
     result = g_dbus_proxy_call_sync ((GDBusProxy *) context,
                                      "GetEngine",               /* method_name */
@@ -1174,9 +1175,17 @@ ibus_input_context_get_engine (IBusInputContext *context)
                                      NULL,                      /* cancellable */
                                      &error                     /* error */
                                      );
-
     if (result == NULL) {
-        g_warning ("%s.GetEngine: %s", IBUS_INTERFACE_INPUT_CONTEXT, error->message);
+        if (g_error_matches (error, IBUS_ERROR, IBUS_ERROR_NO_ENGINE)) {
+            g_debug ("%s.GetEngine: %s",
+                     IBUS_INTERFACE_INPUT_CONTEXT,
+                     error->message);
+        }
+        else {
+            g_warning ("%s.GetEngine: %s",
+                       IBUS_INTERFACE_INPUT_CONTEXT,
+                       error->message);
+        }
         g_error_free (error);
         return NULL;
     }
index 1b8ae2a..19f9f65 100644 (file)
@@ -318,6 +318,7 @@ void
 ibus_init (void)
 {
     g_type_init ();
+    IBUS_ERROR;
     IBUS_TYPE_TEXT;
     IBUS_TYPE_ATTRIBUTE;
     IBUS_TYPE_ATTR_LIST;
index 6a31847..8146719 100644 (file)
@@ -177,6 +177,15 @@ typedef enum {
 } IBusBusRequestNameReply;
 
 /**
+ * IBusError:
+ * @IBUS_ERROR_NO_ENGINE:
+ * There is no engine associated with input context.
+ */
+typedef enum {
+    IBUS_ERROR_NO_ENGINE,
+} IBusError;
+
+/**
  * IBusRectangle:
  * @x: x coordinate.
  * @y: y coordinate.
diff --git a/src/tests/ibus-gi-inputcontext.py b/src/tests/ibus-gi-inputcontext.py
new file mode 100755 (executable)
index 0000000..80fb97b
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# vim:set et sts=4 sw=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2011 Peng Huang <shawn.p.huang@gmail.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+# Boston, MA  02111-1307  USA
+
+
+import glib
+import gio
+from gi.repository import IBus
+IBus.init()
+main = glib.MainLoop()
+bus = IBus.Bus()
+ic = bus.create_input_context("ibus-test")
+ic.get_engine()
+ic.get_engine()
+ic.get_engine()
+ic.get_engine()