From: Peng Huang Date: Wed, 15 Jun 2011 14:38:17 +0000 (-0400) Subject: Add IBUS_ERROR domain and reply IBUS_ERROR_NO_ENGINE in org.freedesktop.IBus.InputCon... X-Git-Tag: 1.4.0~36 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc9dedec30f724e91e7b3bb9111177e96b58ee43;p=platform%2Fupstream%2Fibus.git Add IBUS_ERROR domain and reply IBUS_ERROR_NO_ENGINE in org.freedesktop.IBus.InputContext.GetEngine BUG=None TEST=Manually Review URL: http://codereview.appspot.com/4528140 --- diff --git a/bus/inputcontext.c b/bus/inputcontext.c index bad90ec..1567c5f 100644 --- a/bus/inputcontext.c +++ b/bus/inputcontext.c @@ -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."); } } diff --git a/src/Makefile.am b/src/Makefile.am index 632fc72..a53bd23 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/ibus.h b/src/ibus.h index 8df7160..c408f3d 100644 --- a/src/ibus.h +++ b/src/ibus.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include diff --git a/src/ibuserror.c b/src/ibuserror.c new file mode 100644 index 0000000..c50c164 --- /dev/null +++ b/src/ibuserror.c @@ -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 + * + * 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 +#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 index 0000000..75c64b9 --- /dev/null +++ b/src/ibuserror.h @@ -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 + * + * 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 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 + +G_BEGIN_DECLS + +#define IBUS_ERROR ibus_error_quark() +GQuark ibus_error_quark (void); + +G_END_DECLS +#endif diff --git a/src/ibusinputcontext.c b/src/ibusinputcontext.c index e6f97e8..78d454e 100644 --- a/src/ibusinputcontext.c +++ b/src/ibusinputcontext.c @@ -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; } diff --git a/src/ibusshare.c b/src/ibusshare.c index 1b8ae2a..19f9f65 100644 --- a/src/ibusshare.c +++ b/src/ibusshare.c @@ -318,6 +318,7 @@ void ibus_init (void) { g_type_init (); + IBUS_ERROR; IBUS_TYPE_TEXT; IBUS_TYPE_ATTRIBUTE; IBUS_TYPE_ATTR_LIST; diff --git a/src/ibustypes.h b/src/ibustypes.h index 6a31847..8146719 100644 --- a/src/ibustypes.h +++ b/src/ibustypes.h @@ -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 index 0000000..80fb97b --- /dev/null +++ b/src/tests/ibus-gi-inputcontext.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# vim:set et sts=4 sw=4: +# +# ibus - The Input Bus +# +# Copyright (c) 2011 Peng Huang +# +# 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()