From 164fc1f12467a73c32552292076fd8226873252e Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Wed, 16 Jun 2010 23:47:09 +0800 Subject: [PATCH] Use gdbus in glib, and get rid of libdbus --- Makefile.am | 54 +- autogen.sh | 2 +- bindings/vala/Makefile.am | 6 +- bindings/vala/ibus-1.0/ibus-1.0-custom.vala | 1 - bindings/vala/{ibus-1.0.vapi => ibus-2.0.vapi} | 0 bindings/vala/ibus-2.0/ibus-2.0-custom.vala | 0 .../ibus-2.0.excludes} | 0 .../ibus-1.0.files => ibus-2.0/ibus-2.0.files} | 0 .../{ibus-1.0/ibus-1.0.gi => ibus-2.0/ibus-2.0.gi} | 0 .../ibus-2.0.metadata} | 0 .../ibus-2.0.namespace} | 0 bindings/vala/test/Makefile | 4 +- bus/Makefile.am | 166 ++- bus/connection.c | 206 ++- bus/connection.h | 46 +- bus/dbusimpl.c | 1552 ++++++++++---------- bus/dbusimpl.h | 35 +- bus/engineproxy.c | 655 ++++----- bus/engineproxy.h | 99 +- bus/factoryproxy.c | 172 +-- bus/factoryproxy.h | 17 +- bus/ibusimpl.c | 1103 ++++++-------- bus/ibusimpl.h | 47 +- bus/inputcontext.c | 1198 +++++++-------- bus/inputcontext.h | 55 +- bus/main.c | 46 +- bus/marshalers.list | 13 + bus/matchrule.c | 236 +-- bus/matchrule.h | 95 +- bus/option.h | 5 +- bus/panelproxy.c | 330 ++--- bus/panelproxy.h | 29 +- bus/registry.c | 9 +- bus/registry.h | 4 +- bus/server.c | 161 +- bus/server.h | 54 +- bus/test-matchrule.c | 1 - bus/types.h | 30 + client/gtk2/Makefile.am | 2 +- client/gtk2/ibusim.c | 2 +- client/gtk2/ibusimcontext.c | 3 +- client/gtk3/Makefile.am | 2 +- client/x11/Makefile.am | 2 +- configure.ac | 26 +- debian/libibus-dev.install | 4 +- debian/libibus2.install | 2 +- debian/libibus2.symbols | 154 +- debian/rules | 2 +- docs/reference/ibus/Makefile.am | 2 +- docs/reference/ibus/ibus-sections.txt | 301 ++-- docs/reference/ibus/ibus.types | 3 - gconf/Makefile.am | 6 +- gconf/config.c | 342 +++-- gconf/config.h | 6 +- gconf/main.c | 2 +- ibus-1.0.pc.in => ibus-2.0.pc.in | 6 +- ibus.spec.in | 12 +- ibus/common.py | 2 +- m4/introspection.m4 | 94 ++ memconf/main.cc | 2 +- po/POTFILES.in | 2 - po/ar.po | 11 +- po/as.po | 11 +- po/bn_IN.po | 8 +- po/ca.po | 11 +- po/da.po | 11 +- po/de.po | 23 +- po/es.po | 127 +- po/fr.po | 19 +- po/gu.po | 2 +- po/hi.po | 9 +- po/hu.po | 11 +- po/it.po | 17 +- po/ja.po | 3 +- po/kn.po | 9 +- po/ko.po | 4 +- po/ml.po | 7 +- po/mr.po | 8 +- po/or.po | 7 +- po/pa.po | 11 +- po/pl.po | 11 +- po/pt_BR.po | 20 +- po/ru.po | 17 +- po/sr.po | 15 +- po/sr@latin.po | 15 +- po/ta.po | 6 +- po/te.po | 7 +- po/vi.po | 11 +- po/zh_CN.po | 4 +- po/zh_HK.po | 11 +- po/zh_TW.po | 11 +- src/Makefile.am | 392 +++-- src/ibus.h | 11 +- src/ibusattribute.c | 76 +- src/ibusattribute.h | 5 + src/ibusattrlist.c | 70 +- src/ibusattrlist.h | 5 + src/ibusbus.c | 946 +++++------- src/ibusbus.h | 16 +- src/ibuscomponent.c | 199 +-- src/ibuscomponent.h | 8 + src/ibusconfig.c | 295 ++-- src/ibusconfig.h | 23 +- src/ibusconfigprivate.h | 5 + src/ibusconfigservice.c | 448 +++--- src/ibusconfigservice.h | 48 +- src/ibusconnection.c | 839 ----------- src/ibusconnection.h | 520 ------- src/ibusdbus.h | 5 + src/ibusdebug.h | 5 + src/ibusengine.c | 998 ++++++------- src/ibusengine.h | 35 +- src/ibusenginedesc.c | 139 +- src/ibusenginedesc.h | 5 + src/ibusenumtypes.c.template | 1 - src/ibuserror.c | 90 -- src/ibuserror.h | 89 -- src/ibusfactory.c | 346 ++--- src/ibusfactory.h | 13 +- src/ibushotkey.c | 44 +- src/ibushotkey.h | 5 + src/ibusinputcontext.c | 837 +++++------ src/ibusinputcontext.h | 22 +- src/ibusinternal.c | 671 --------- src/ibusinternal.h | 48 +- src/ibuskeymap.c | 6 +- src/ibuskeymap.h | 5 + src/ibuskeysyms.h | 5 + src/ibuslookuptable.c | 159 +- src/ibuslookuptable.h | 5 + src/ibusmainloop.c | 52 - src/ibusmainloop.h | 112 -- src/ibusmarshalers.list | 2 +- src/ibusmessage.c | 1027 ------------- src/ibusmessage.h | 935 ------------ src/ibusobject.c | 53 +- src/ibusobject.h | 16 +- src/ibusobservedpath.c | 51 +- src/ibusobservedpath.h | 5 + src/ibuspanelservice.c | 821 +++++------ src/ibuspanelservice.h | 100 +- src/ibuspendingcall.c | 106 -- src/ibuspendingcall.h | 210 --- src/ibusproperty.c | 117 +- src/ibusproperty.h | 5 + src/ibusproplist.c | 74 +- src/ibusproplist.h | 5 + src/ibusproxy.c | 715 +-------- src/ibusproxy.h | 221 +-- src/ibusserializable.c | 375 ++--- src/ibusserializable.h | 35 +- src/ibusserver.c | 12 +- src/ibusservice.c | 722 +++++---- src/ibusservice.h | 171 ++- src/ibusshare.c | 25 +- src/ibusshare.h | 5 + src/ibustext.c | 60 +- src/ibustext.h | 5 + src/ibustypes.h | 5 + src/ibusxml.h | 5 + src/test-attribute.c | 45 - src/test-bus.c | 102 -- src/test-keynames.c | 9 - src/test-lookuptable.c | 41 - src/test-text.c | 43 - src/tests/Makefile.am | 65 + src/tests/ibus-bus.c | 130 ++ src/tests/ibus-configservice.c | 43 + src/{test-engine.c => tests/ibus-engine.c} | 0 src/tests/ibus-factory.c | 43 + .../ibus-global-engine.c} | 1 + src/{test-keymap.c => tests/ibus-keymap.c} | 0 src/tests/ibus-keynames.c | 20 + src/{test-proxy.c => tests/ibus-proxy.c} | 0 src/tests/ibus-serializable.c | 147 ++ src/{test-server.c => tests/ibus-server.c} | 0 src/tests/ibus-share.c | 24 + 177 files changed, 7802 insertions(+), 14244 deletions(-) delete mode 100644 bindings/vala/ibus-1.0/ibus-1.0-custom.vala rename bindings/vala/{ibus-1.0.vapi => ibus-2.0.vapi} (100%) create mode 100644 bindings/vala/ibus-2.0/ibus-2.0-custom.vala rename bindings/vala/{ibus-1.0/ibus-1.0.excludes => ibus-2.0/ibus-2.0.excludes} (100%) rename bindings/vala/{ibus-1.0/ibus-1.0.files => ibus-2.0/ibus-2.0.files} (100%) rename bindings/vala/{ibus-1.0/ibus-1.0.gi => ibus-2.0/ibus-2.0.gi} (100%) rename bindings/vala/{ibus-1.0/ibus-1.0.metadata => ibus-2.0/ibus-2.0.metadata} (100%) rename bindings/vala/{ibus-1.0/ibus-1.0.namespace => ibus-2.0/ibus-2.0.namespace} (100%) create mode 100644 bus/marshalers.list create mode 100644 bus/types.h rename ibus-1.0.pc.in => ibus-2.0.pc.in (60%) create mode 100644 m4/introspection.m4 delete mode 100644 src/ibusconnection.c delete mode 100644 src/ibusconnection.h delete mode 100644 src/ibuserror.c delete mode 100644 src/ibuserror.h delete mode 100644 src/ibusinternal.c delete mode 100644 src/ibusmainloop.c delete mode 100644 src/ibusmainloop.h delete mode 100644 src/ibusmessage.c delete mode 100644 src/ibusmessage.h delete mode 100644 src/ibuspendingcall.c delete mode 100644 src/ibuspendingcall.h delete mode 100644 src/test-attribute.c delete mode 100644 src/test-bus.c delete mode 100644 src/test-keynames.c delete mode 100644 src/test-lookuptable.c delete mode 100644 src/test-text.c create mode 100644 src/tests/Makefile.am create mode 100644 src/tests/ibus-bus.c create mode 100644 src/tests/ibus-configservice.c rename src/{test-engine.c => tests/ibus-engine.c} (100%) create mode 100644 src/tests/ibus-factory.c rename src/{test-global-engine.c => tests/ibus-global-engine.c} (98%) rename src/{test-keymap.c => tests/ibus-keymap.c} (100%) create mode 100644 src/tests/ibus-keynames.c rename src/{test-proxy.c => tests/ibus-proxy.c} (100%) create mode 100644 src/tests/ibus-serializable.c rename src/{test-server.c => tests/ibus-server.c} (100%) create mode 100644 src/tests/ibus-share.c diff --git a/Makefile.am b/Makefile.am index 7895940..ffde26c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,16 +20,25 @@ # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA +NULL = + if ENABLE_PYTHON -PYTHON_DIRS = \ - ibus \ - setup \ +PYTHON_DIRS = \ + ibus \ + ui \ + setup \ $(NULL) endif if ENABLE_GCONF -GCONF_DIRS = \ - gconf \ +GCONF_DIRS = \ + gconf \ + $(NULL) +endif + +if ENABLE_DAEMON +DAEMON_DIRS = \ + bus \ $(NULL) endif @@ -39,30 +48,29 @@ MEMCONF_DIRS = \ $(NULL) endif -SUBDIRS = \ - src \ - bus \ - util \ - client \ - data \ - m4 \ - po \ - docs \ - ui \ - bindings \ - $(PYTHON_DIRS) \ - $(GCONF_DIRS) \ +SUBDIRS = \ + src \ + util \ + client \ + data \ + m4 \ + po \ + docs \ + bindings \ + $(DAEMON_DIRS) \ + $(PYTHON_DIRS) \ + $(GCONF_DIRS) \ $(MEMCONF_DIRS) \ $(NULL) ACLOCAL_AMFLAGS = -I m4 pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = ibus-1.0.pc +pkgconfig_DATA = ibus-2.0.pc EXTRA_DIST = \ autogen.sh \ - ibus-1.0.pc.in \ + ibus-2.0.pc.in \ ibus.spec.in \ python-config.py \ $(NULL) @@ -80,6 +88,7 @@ install-data-hook: DISTCHECK_CONFIGURE_FLAGS = \ --enable-gtk-doc \ --disable-schemas-install \ + --disable-introspection \ $(NULL) dist-hook: @@ -143,10 +152,9 @@ dpkg: dist debian/changelog cd $(distdir); \ cp -a ../../debian . ; \ cd debian; \ - debuild -b ; \ + debuild -b -us -uc; \ ) - clean-rpm: $(RM) -r "`uname -i`" @@ -156,4 +164,4 @@ git-tag: git tag -s @PACKAGE_VERSION@ git-clean-tree: - git clean -d -f -x + git clean -d -f -x diff --git a/autogen.sh b/autogen.sh index cf50e42..1861f1b 100755 --- a/autogen.sh +++ b/autogen.sh @@ -22,4 +22,4 @@ which gnome-autogen.sh || { touch $srcdir/ChangeLog } -ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4" REQUIRED_AUTOMAKE_VERSION=1.10 CFLAGS="-Wall -Werror" . gnome-autogen.sh +ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4" REQUIRED_AUTOMAKE_VERSION=1.10 CFLAGS="-Wall -Werror $CFLAGS" . gnome-autogen.sh diff --git a/bindings/vala/Makefile.am b/bindings/vala/Makefile.am index 26b6494..72597d3 100644 --- a/bindings/vala/Makefile.am +++ b/bindings/vala/Makefile.am @@ -22,8 +22,8 @@ vapidir = $(datadir)/vala/vapi dist_vapi_DATA = \ - ibus-1.0.vapi \ + ibus-2.0.vapi \ $(NULL) -ibus-1.0.vapi: - vapigen --library ibus-1.0 ibus-1.0/ibus-1.0.gi ibus-1.0/ibus-1.0-custom.vala +ibus-2.0.vapi: + vapigen --library ibus-2.0 ibus-2.0/ibus-2.0.gi ibus-2.0/ibus-2.0-custom.vala diff --git a/bindings/vala/ibus-1.0/ibus-1.0-custom.vala b/bindings/vala/ibus-1.0/ibus-1.0-custom.vala deleted file mode 100644 index 8b13789..0000000 --- a/bindings/vala/ibus-1.0/ibus-1.0-custom.vala +++ /dev/null @@ -1 +0,0 @@ - diff --git a/bindings/vala/ibus-1.0.vapi b/bindings/vala/ibus-2.0.vapi similarity index 100% rename from bindings/vala/ibus-1.0.vapi rename to bindings/vala/ibus-2.0.vapi diff --git a/bindings/vala/ibus-2.0/ibus-2.0-custom.vala b/bindings/vala/ibus-2.0/ibus-2.0-custom.vala new file mode 100644 index 0000000..e69de29 diff --git a/bindings/vala/ibus-1.0/ibus-1.0.excludes b/bindings/vala/ibus-2.0/ibus-2.0.excludes similarity index 100% rename from bindings/vala/ibus-1.0/ibus-1.0.excludes rename to bindings/vala/ibus-2.0/ibus-2.0.excludes diff --git a/bindings/vala/ibus-1.0/ibus-1.0.files b/bindings/vala/ibus-2.0/ibus-2.0.files similarity index 100% rename from bindings/vala/ibus-1.0/ibus-1.0.files rename to bindings/vala/ibus-2.0/ibus-2.0.files diff --git a/bindings/vala/ibus-1.0/ibus-1.0.gi b/bindings/vala/ibus-2.0/ibus-2.0.gi similarity index 100% rename from bindings/vala/ibus-1.0/ibus-1.0.gi rename to bindings/vala/ibus-2.0/ibus-2.0.gi diff --git a/bindings/vala/ibus-1.0/ibus-1.0.metadata b/bindings/vala/ibus-2.0/ibus-2.0.metadata similarity index 100% rename from bindings/vala/ibus-1.0/ibus-1.0.metadata rename to bindings/vala/ibus-2.0/ibus-2.0.metadata diff --git a/bindings/vala/ibus-1.0/ibus-1.0.namespace b/bindings/vala/ibus-2.0/ibus-2.0.namespace similarity index 100% rename from bindings/vala/ibus-1.0/ibus-1.0.namespace rename to bindings/vala/ibus-2.0/ibus-2.0.namespace diff --git a/bindings/vala/test/Makefile b/bindings/vala/test/Makefile index abe55a7..91771cb 100644 --- a/bindings/vala/test/Makefile +++ b/bindings/vala/test/Makefile @@ -1,3 +1,3 @@ ibus-engine-vala: test.vala - valac --pkg ibus-1.0 --pkg enchant $^ -C - valac -g --pkg ibus-1.0 --pkg enchant $^ -o $@ + valac --vapidir .. --pkg ibus-2.0 --pkg enchant $^ -C + valac -g --vapidir .. --pkg ibus-2.0 --pkg enchant $^ -o $@ diff --git a/bus/Makefile.am b/bus/Makefile.am index 764edc7..751f9b9 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -20,40 +20,33 @@ # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA -libibus = $(top_builddir)/src/libibus.la +NULL = -INCLUDES = \ - -I$(top_srcdir)/src \ +libibus = $(top_builddir)/src/libibus-2.0.la + +INCLUDES = \ + -I$(top_srcdir)/src \ -I$(top_builddir)/src \ $(NULL) -AM_CFLAGS = \ - @GLIB2_CFLAGS@ \ - @GTHREAD2_CFLAGS@ \ - @DBUS_CFLAGS@ \ - -DG_LOG_DOMAIN=\"IBUS\" \ +AM_CFLAGS = \ + @GLIB2_CFLAGS@ \ + @GIO2_CFLAGS@ \ + @GTHREAD2_CFLAGS@ \ + -DG_LOG_DOMAIN=\"IBUS\" \ -DPKGDATADIR=\"$(pkgdatadir)\" \ -DLIBEXECDIR=\"$(libexecdir)\" \ - -DBINDIR=\"@bindir@\" \ - $(INCLUDES) \ + -DBINDIR=\"@bindir@\" \ + $(INCLUDES) \ $(NULL) -AM_LDADD = \ - @GOBJECT2_LIBS@ \ - @GLIB2_LIBS@ \ - @GTHREAD2_LIBS@ \ - @DBUS_LIBS@ \ - $(libibus) \ +AM_LDADD = \ + @GOBJECT2_LIBS@ \ + @GLIB2_LIBS@ \ + @GIO2_LIBS@ \ + @GTHREAD2_LIBS@ \ + $(libibus) \ $(NULL) -TESTS = \ - test-matchrule \ - test-stress \ - $(NULL) -xdgautostart_DATA = \ - ibus.desktop \ - $(NULL) -xdgautostartdir = $(sysconfdir)/xdg/autostart - desktopdir = $(datadir)/applications desktop_in_files = ibus.desktop.in desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) @@ -61,59 +54,77 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) noinst_PROGRAMS = $(TESTS) bin_PROGRAMS = ibus-daemon -ibus_daemon_DEPENDENCIES = \ - $(libibus) \ - $(NULL) -ibus_daemon_SOURCES = \ - main.c \ - dbusimpl.c \ - dbusimpl.h \ - ibusimpl.c \ - ibusimpl.h \ - inputcontext.c \ - inputcontext.h \ - engineproxy.c \ - engineproxy.h \ - panelproxy.c \ - panelproxy.h \ - factoryproxy.c \ - factoryproxy.h \ - server.c \ - server.h \ - connection.c \ - connection.h \ - matchrule.c \ - matchrule.h \ - registry.c \ - registry.h \ - option.h \ +ibus_daemon_DEPENDENCIES = \ + $(libibus) \ + $(NULL) +ibus_daemon_SOURCES = \ + main.c \ + dbusimpl.c \ + dbusimpl.h \ + ibusimpl.c \ + ibusimpl.h \ + inputcontext.c \ + inputcontext.h \ + engineproxy.c \ + engineproxy.h \ + panelproxy.c \ + panelproxy.h \ + factoryproxy.c \ + factoryproxy.h \ + server.c \ + server.h \ + connection.c \ + connection.h \ + matchrule.c \ + matchrule.h \ + registry.c \ + registry.h \ + option.h \ + marshalers.c \ + marshalers.h \ + types.h \ + $(NULL) +ibus_daemon_CFLAGS = \ + $(AM_CFLAGS) \ + $(NULL) +ibus_daemon_LDADD = \ + $(AM_LDADD) \ $(NULL) -ibus_daemon_CFLAGS = \ - $(AM_CFLAGS) \ - $(NULL) -ibus_daemon_LDADD = \ - $(AM_LDADD) \ + +BUILT_SOURCES = \ + marshalers.h \ + marshalers.c \ $(NULL) -# test_registry_SOURCES = \ -# registry.c \ -# registry.h \ -# factoryproxy.c \ -# factoryproxy.h \ -# test-registry.c \ +# test_registry_SOURCES = \ +# registry.c \ +# registry.h \ +# factoryproxy.c \ +# factoryproxy.h \ +# test-registry.c \ +# $(NULL) +# +# test_matchrule_SOURCES = \ +# connection.c \ +# matchrule.c \ +# test-matchrule.c \ +# $(NULL) +# test_matchrule_CFLAGS = \ +# $(AM_CFLAGS) \ +# $(NULL) +# test_matchrule_LDADD = \ +# $(AM_LDADD) \ # $(NULL) -test_matchrule_SOURCES = \ - connection.c \ - matchrule.c \ - test-matchrule.c \ - $(NULL) -test_matchrule_CFLAGS = \ - $(AM_CFLAGS) \ - $(NULL) -test_matchrule_LDADD = \ - $(AM_LDADD) \ - $(NULL) +# gen marshal +marshalers.h: marshalers.list + $(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=bus_marshal $(srcdir)/marshalers.list --header --internal > $@.tmp && \ + mv $@.tmp $@ + +marshalers.c: marshalers.h marshalers.list + $(AM_V_GEN) (echo "#include \"marshalers.h\""; \ + $(GLIB_GENMARSHAL) --prefix=bus_marshal $(srcdir)/marshalers.list --body --internal) > $@.tmp && \ + mv $@.tmp $@ test_stress_SOURCES = \ test-client.c \ @@ -131,12 +142,13 @@ test_stress_LDADD = \ @X11_LIBS@ \ $(NULL) -EXTRA_DIST = \ - $(desktop_in_files) \ +EXTRA_DIST = \ + $(desktop_in_files) \ + marshalers.list \ $(NULL) -DISTCLEANFILES = \ - $(desktop_DATA) \ +DISTCLEANFILES = \ + $(desktop_DATA) \ $(NULL) $(libibus): diff --git a/bus/connection.c b/bus/connection.c index 5a84c2e..0b8bec7 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -24,49 +24,48 @@ #include "connection.h" #include "matchrule.h" -#define BUS_CONNECTION_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), BUS_TYPE_CONNECTION, BusConnectionPrivate)) +struct _BusConnection { + IBusObject parent; + + /* instance members */ + GDBusConnection *connection; + gchar *unique_name; + /* list for well known names */ + GList *names; + GList *rules; + guint filter_id; +}; + +struct _BusConnectionClass { + IBusObjectClass parent; -/* BusConnectionPriv */ -struct _BusConnectionPrivate { + /* class members */ }; -typedef struct _BusConnectionPrivate BusConnectionPrivate; // static guint _signals[LAST_SIGNAL] = { 0 }; /* functions prototype */ -static void bus_connection_destroy (BusConnection *connection); -static gboolean bus_connection_authenticate_unix_user - (IBusConnection *connection, - gulong uid); -static gboolean bus_connection_ibus_message (BusConnection *connection, - IBusMessage *message); -#if 0 -static gboolean bus_connection_dbus_signal (BusConnection *connection, - DBusMessage *message); -#endif - -G_DEFINE_TYPE (BusConnection, bus_connection, IBUS_TYPE_CONNECTION) +static void bus_connection_destroy (BusConnection *connection); +static void bus_connection_set_dbus_connection + (BusConnection *connection, + GDBusConnection *dbus_connection); +static void bus_connection_dbus_connection_closed_cb + (GDBusConnection *dbus_connection, + gboolean remote_peer_vanished, + GError *error, + BusConnection *connection); +static GQuark bus_connection_quark (void); -BusConnection * -bus_connection_new (void) -{ - BusConnection *connection = BUS_CONNECTION (g_object_new (BUS_TYPE_CONNECTION, NULL)); - return connection; -} +#define BUS_CONNECTION_QUARK (bus_connection_quark ()) + +G_DEFINE_TYPE (BusConnection, bus_connection, IBUS_TYPE_OBJECT) static void bus_connection_class_init (BusConnectionClass *klass) { IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - IBusConnectionClass *ibus_connection_class = IBUS_CONNECTION_CLASS (klass); ibus_object_class->destroy = (IBusObjectDestroyFunc) bus_connection_destroy; - - ibus_connection_class->authenticate_unix_user = bus_connection_authenticate_unix_user; - ibus_connection_class->ibus_message = - (IBusIBusMessageFunc) bus_connection_ibus_message; - } static void @@ -79,61 +78,84 @@ bus_connection_init (BusConnection *connection) static void bus_connection_destroy (BusConnection *connection) { - GList *name; - - IBUS_OBJECT_CLASS(bus_connection_parent_class)->destroy (IBUS_OBJECT (connection)); + if (connection->connection) { + /* disconnect from closed signal */ + g_signal_handlers_disconnect_by_func (connection->connection, + G_CALLBACK (bus_connection_dbus_connection_closed_cb), connection); + + /* remove filter */ + bus_connection_set_filter (connection, NULL, NULL, NULL); + + /* disconnect busconnection with dbus connection */ + g_object_set_qdata ((GObject *)connection->connection, BUS_CONNECTION_QUARK, NULL); + if (!g_dbus_connection_is_closed (connection->connection)) { + g_dbus_connection_close (connection->connection, NULL, NULL, NULL); + } + g_object_unref (connection->connection); + connection->connection = NULL; + } if (connection->unique_name) { g_free (connection->unique_name); connection->unique_name = NULL; } - for (name = connection->names; name != NULL; name = name->next) { - g_free (name->data); - } + g_list_foreach (connection->names, (GFunc) g_free, NULL); g_list_free (connection->names); connection->names = NULL; + + IBUS_OBJECT_CLASS(bus_connection_parent_class)->destroy (IBUS_OBJECT (connection)); } -static gboolean -bus_connection_authenticate_unix_user (IBusConnection *connection, - gulong uid) +static void +bus_connection_dbus_connection_closed_cb (GDBusConnection *dbus_connection, + gboolean remote_peer_vanished, + GError *error, + BusConnection *connection) { - /* just allow root or same user connect to ibus */ - if (uid == 0 || uid == getuid ()) - return TRUE; - return FALSE; + ibus_object_destroy ((IBusObject *)connection); } -static gboolean -bus_connection_ibus_message (BusConnection *connection, - IBusMessage *message) +static void +bus_connection_set_dbus_connection (BusConnection *connection, + GDBusConnection *dbus_connection) { - gboolean retval; + connection->connection = dbus_connection; + g_object_ref (connection->connection); + g_object_set_qdata_full ((GObject *)dbus_connection, + BUS_CONNECTION_QUARK, + g_object_ref (connection), + (GDestroyNotify)g_object_unref); + g_signal_connect (connection->connection, "closed", + G_CALLBACK (bus_connection_dbus_connection_closed_cb), connection); +} -#if 0 - gchar *str = ibus_message_to_string (message); - g_debug ("%s", str); - g_free(str); -#endif +static GQuark +bus_connection_quark (void) +{ + GQuark quark = 0; + if (quark == 0) { + quark = g_quark_from_static_string ("BUS_CONNECTION"); + } + return quark; +} - retval = IBUS_CONNECTION_CLASS (bus_connection_parent_class)->ibus_message ( - (IBusConnection *)connection, - message); - return retval; +BusConnection * +bus_connection_new (GDBusConnection *dbus_connection) +{ + g_return_val_if_fail (bus_connection_lookup (dbus_connection) == NULL, NULL); + BusConnection * connection = BUS_CONNECTION (g_object_new (BUS_TYPE_CONNECTION, NULL)); + bus_connection_set_dbus_connection (connection, dbus_connection); + return connection; } -#if 0 -static gboolean -bus_connection_dbus_signal (BusConnection *connection, - DBusMessage *message) +BusConnection * +bus_connection_lookup (GDBusConnection *dbus_connection) { - gboolean retval; - retval = IBUS_CONNECTION_CLASS (bus_connection_parent_class)->dbus_signal ( - IBUS_CONNECTION (connection), message); - return retval; + g_return_val_if_fail (G_IS_DBUS_CONNECTION (dbus_connection), NULL); + return (BusConnection *) g_object_get_qdata ((GObject *)dbus_connection, + BUS_CONNECTION_QUARK); } -#endif const gchar * bus_connection_get_unique_name (BusConnection *connection) @@ -171,13 +193,11 @@ gboolean bus_connection_remove_name (BusConnection *connection, const gchar *name) { - GList *link; - - link = g_list_find_custom (connection->names, name, (GCompareFunc) g_strcmp0); + GList *list = g_list_find_custom (connection->names, name, (GCompareFunc) g_strcmp0); - if (link) { - g_free (link->data); - connection->names = g_list_delete_link (connection->names, link); + if (list) { + g_free (list->data); + connection->names = g_list_delete_link (connection->names, list); return TRUE; } return FALSE; @@ -190,29 +210,55 @@ bus_connection_add_match (BusConnection *connection, g_assert (BUS_IS_CONNECTION (connection)); g_assert (rule != NULL); - BusMatchRule *p; - GList *link; - - p = bus_match_rule_new (rule); - if (p == NULL) + BusMatchRule *match = bus_match_rule_new (rule); + if (match == NULL) return FALSE; - for (link = connection->rules; link != NULL; link = link->next) { - if (bus_match_rule_is_equal (p, (BusMatchRule *)link->data)) { - g_object_unref (p); + GList *list; + for (list = connection->rules; list != NULL; list = list->next) { + if (bus_match_rule_is_equal (match, (BusMatchRule *)list->data)) { + g_object_unref (match); return TRUE; } } - connection->rules = g_list_append (connection->rules, p); + connection->rules = g_list_append (connection->rules, match); return TRUE; - } gboolean bus_connection_remove_match (BusConnection *connection, const gchar *rule) { + g_assert (BUS_IS_CONNECTION (connection)); return FALSE; } +GDBusConnection * +bus_connection_get_dbus_connection (BusConnection *connection) +{ + g_assert (BUS_IS_CONNECTION (connection)); + return connection->connection; +} + + +void +bus_connection_set_filter (BusConnection *connection, + GDBusMessageFilterFunction filter_func, + gpointer user_data, + GDestroyNotify user_data_free_func) +{ + g_assert (BUS_IS_CONNECTION (connection)); + + if (connection->filter_id != 0) { + g_dbus_connection_remove_filter (connection->connection, connection->filter_id); + connection->filter_id = 0; + } + + if (filter_func != NULL) { + connection->filter_id = g_dbus_connection_add_filter (connection->connection, + filter_func, + user_data, + user_data_free_func); + } +} diff --git a/bus/connection.h b/bus/connection.h index b755045..a4fa02c 100644 --- a/bus/connection.h +++ b/bus/connection.h @@ -19,8 +19,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __CONNECTION_H_ -#define __CONNECTION_H_ +#ifndef __BUS_CONNECTION_H_ +#define __BUS_CONNECTION_H_ #include @@ -47,32 +47,24 @@ G_BEGIN_DECLS typedef struct _BusConnection BusConnection; typedef struct _BusConnectionClass BusConnectionClass; -struct _BusConnection { - IBusConnection parent; - - /* instance members */ - gchar *unique_name; - /* list for well known names */ - GList *names; - GList *rules; -}; - -struct _BusConnectionClass { - IBusConnectionClass parent; - - /* class members */ -}; - GType bus_connection_get_type (void); -BusConnection *bus_connection_new (void); -const gchar *bus_connection_get_unique_name (BusConnection *connection); -void bus_connection_set_unique_name (BusConnection *connection, - const gchar *name); -const GList *bus_connection_get_names (BusConnection *connection); -const gchar *bus_connection_add_name (BusConnection *connection, - const gchar *name); -gboolean bus_connection_remove_name (BusConnection *connection, - const gchar *name); +BusConnection *bus_connection_new (GDBusConnection *connection); +BusConnection *bus_connection_lookup (GDBusConnection *connection); +const gchar *bus_connection_get_unique_name (BusConnection *connection); +void bus_connection_set_unique_name (BusConnection *connection, + const gchar *name); +const GList *bus_connection_get_names (BusConnection *connection); +const gchar *bus_connection_add_name (BusConnection *connection, + const gchar *name); +gboolean bus_connection_remove_name (BusConnection *connection, + const gchar *name); +GDBusConnection *bus_connection_get_dbus_connection (BusConnection *connection); +void bus_connection_set_filter (BusConnection *connection, + GDBusMessageFilterFunction + filter_func, + gpointer user_data, + GDestroyNotify user_data_free_func); + G_END_DECLS #endif diff --git a/bus/dbusimpl.c b/bus/dbusimpl.c index f4a758d..12f520a 100644 --- a/bus/dbusimpl.c +++ b/bus/dbusimpl.c @@ -19,18 +19,13 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ - -#include -#include -#include -#include #include "dbusimpl.h" -#include "connection.h" +#include +#include "types.h" +#include "marshalers.h" #include "matchrule.h" enum { - NAME_ACQUIRED, - NAME_LOST, NAME_OWNER_CHANGED, LAST_SIGNAL, }; @@ -41,64 +36,193 @@ enum { static guint dbus_signals[LAST_SIGNAL] = { 0 }; +struct _BusDBusImpl { + IBusService parent; + /* instance members */ + GHashTable *unique_names; + GHashTable *names; + GList *objects; + GList *connections; + GList *rules; + gint id; + + GMutex *dispatch_lock; + GList *dispatch_queue; + + GMutex *forward_lock; + GList *forward_queue; +}; + +struct _BusDBusImplClass { + IBusServiceClass parent; + + /* class members */ + void (* name_owner_changed) (BusDBusImpl *dbus, + gchar *name, + gchar *old_name, + gchar *new_name); +}; + +typedef struct _BusDispatchData BusDispatchData; +struct _BusDispatchData { + GDBusMessage *message; + BusConnection *skip_connection; +}; + + /* functions prototype */ static void bus_dbus_impl_destroy (BusDBusImpl *dbus); -static gboolean bus_dbus_impl_ibus_message (BusDBusImpl *dbus, - BusConnection *connection, - IBusMessage *message); -static void bus_dbus_impl_name_owner_changed(BusDBusImpl *dbus, +static void bus_dbus_impl_service_method_call + (IBusService *service, + GDBusConnection *dbus_connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation + *invocation); +static GVariant *bus_dbus_impl_service_get_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error); +static gboolean bus_dbus_impl_service_set_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error); +static void bus_dbus_impl_name_owner_changed + (BusDBusImpl *dbus, gchar *name, gchar *old_name, gchar *new_name); - - -static void _connection_destroy_cb (BusConnection *connection, +static void bus_dbus_impl_connection_destroy_cb + (BusConnection *connection, BusDBusImpl *dbus); -static void _rule_destroy_cb (BusMatchRule *rule, +static void bus_dbus_impl_rule_destroy_cb (BusMatchRule *rule, + BusDBusImpl *dbus); +static void bus_dbus_impl_object_destroy_cb(IBusService *object, BusDBusImpl *dbus); G_DEFINE_TYPE(BusDBusImpl, bus_dbus_impl, IBUS_TYPE_SERVICE) -BusDBusImpl * -bus_dbus_impl_get_default (void) -{ - static BusDBusImpl *dbus = NULL; - - if (dbus == NULL) { - dbus = (BusDBusImpl *) g_object_new (BUS_TYPE_DBUS_IMPL, - "path", DBUS_PATH_DBUS, - NULL); - } - - return dbus; -} +static const gchar introspection_xml[] = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; static void -bus_dbus_impl_class_init (BusDBusImplClass *klass) +bus_dbus_impl_class_init (BusDBusImplClass *class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - IBusServiceClass *service_class = IBUS_SERVICE_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (class); IBUS_OBJECT_CLASS (gobject_class)->destroy = (IBusObjectDestroyFunc) bus_dbus_impl_destroy; - service_class->ibus_message = (ServiceIBusMessageFunc) bus_dbus_impl_ibus_message; + IBUS_SERVICE_CLASS (class)->service_method_call = bus_dbus_impl_service_method_call; + IBUS_SERVICE_CLASS (class)->service_get_property = bus_dbus_impl_service_get_property; + IBUS_SERVICE_CLASS (class)->service_set_property = bus_dbus_impl_service_set_property; + + ibus_service_class_add_interfaces (IBUS_SERVICE_CLASS (class), introspection_xml); - klass->name_owner_changed = bus_dbus_impl_name_owner_changed; + class->name_owner_changed = bus_dbus_impl_name_owner_changed; /* install signals */ dbus_signals[NAME_OWNER_CHANGED] = g_signal_new (I_("name-owner-changed"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (BusDBusImplClass, name_owner_changed), NULL, NULL, - ibus_marshal_VOID__STRING_STRING_STRING, + bus_marshal_VOID__STRING_STRING_STRING, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - } static void @@ -106,13 +230,9 @@ bus_dbus_impl_init (BusDBusImpl *dbus) { dbus->unique_names = g_hash_table_new (g_str_hash, g_str_equal); dbus->names = g_hash_table_new (g_str_hash, g_str_equal); - dbus->objects = g_hash_table_new (g_str_hash, g_str_equal); - dbus->connections = NULL; - dbus->rules = NULL; - dbus->id = 1; - g_object_ref (dbus); - g_hash_table_insert (dbus->objects, DBUS_PATH_DBUS, dbus); + dbus->dispatch_lock = g_mutex_new (); + dbus->forward_lock = g_mutex_new (); } static void @@ -120,9 +240,19 @@ bus_dbus_impl_destroy (BusDBusImpl *dbus) { GList *p; + for (p = dbus->objects; p != NULL; p = p->next) { + IBusService *object = (IBusService *)p->data; + g_signal_handlers_disconnect_by_func (object, G_CALLBACK (bus_dbus_impl_object_destroy_cb), dbus); + ibus_object_destroy ((IBusObject *)object); + g_object_unref (object); + } + g_list_free (dbus->objects); + dbus->objects = NULL; + for (p = dbus->rules; p != NULL; p = p->next) { BusMatchRule *rule = BUS_MATCH_RULE (p->data); - g_signal_handlers_disconnect_by_func (rule, _rule_destroy_cb, dbus); + g_signal_handlers_disconnect_by_func (rule, + G_CALLBACK (bus_dbus_impl_rule_destroy_cb), dbus); ibus_object_destroy ((IBusObject *) rule); g_object_unref (rule); } @@ -130,10 +260,10 @@ bus_dbus_impl_destroy (BusDBusImpl *dbus) dbus->rules = NULL; for (p = dbus->connections; p != NULL; p = p->next) { - BusConnection *connection = BUS_CONNECTION (p->data); - g_signal_handlers_disconnect_by_func (connection, _connection_destroy_cb, dbus); - ibus_connection_close ((IBusConnection *) connection); - ibus_object_destroy ((IBusObject *) connection); + GDBusConnection *connection = G_DBUS_CONNECTION (p->data); + g_signal_handlers_disconnect_by_func (connection, bus_dbus_impl_connection_destroy_cb, dbus); + /* FIXME should handle result? */ + g_dbus_connection_close (connection, NULL, NULL, NULL); g_object_unref (connection); } g_list_free (dbus->connections); @@ -141,174 +271,31 @@ bus_dbus_impl_destroy (BusDBusImpl *dbus) g_hash_table_remove_all (dbus->unique_names); g_hash_table_remove_all (dbus->names); - g_hash_table_remove_all (dbus->objects); dbus->unique_names = NULL; dbus->names = NULL; - dbus->objects = NULL; - G_OBJECT_CLASS(bus_dbus_impl_parent_class)->dispose (G_OBJECT (dbus)); + IBUS_OBJECT_CLASS(bus_dbus_impl_parent_class)->destroy ((IBusObject *)dbus); } - -/* introspectable interface */ -static IBusMessage * -_dbus_introspect (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) -{ - static const gchar *introspect = - DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" -#if 0 - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" -#endif - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" -#if 0 - " \n" - " \n" - " \n" -#endif - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" -#if 0 - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" -#endif - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" -#if 0 - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" -#endif - " \n" - "\n"; - - IBusMessage *reply_message; - reply_message = ibus_message_new_method_return (message); - ibus_message_append_args (reply_message, - G_TYPE_STRING, &introspect, - G_TYPE_INVALID); - - return reply_message; -} - - -/* dbus interface */ -static IBusMessage * -_dbus_no_implement (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) -{ - IBusMessage *reply_message; - reply_message = ibus_message_new_error_printf (message, - DBUS_ERROR_UNKNOWN_METHOD, - "IBus does not support %s.", - ibus_message_get_member (message)); - return reply_message; -} - - -static IBusMessage * -_dbus_hello (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) +static void +bus_dbus_impl_hello (BusDBusImpl *dbus, + BusConnection *connection, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply_message; - if (bus_connection_get_unique_name (connection) != NULL) { - reply_message = ibus_message_new_error (message, - DBUS_ERROR_FAILED, - "Already handled an Hello message"); + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Already handled an Hello message"); } else { - gchar *name; - - name = g_strdup_printf (":1.%d", dbus->id ++); + gchar *name = g_strdup_printf (":1.%d", ++dbus->id); bus_connection_set_unique_name (connection, name); g_free (name); name = (gchar *) bus_connection_get_unique_name (connection); g_hash_table_insert (dbus->unique_names, name, connection); - - reply_message = ibus_message_new_method_return (message); - ibus_message_append_args (reply_message, - G_TYPE_STRING, &name, - G_TYPE_INVALID); - - ibus_connection_send ((IBusConnection *) connection, reply_message); - ibus_message_unref (reply_message); - ibus_connection_flush ((IBusConnection *) connection); - reply_message = NULL; + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", name)); g_signal_emit (dbus, dbus_signals[NAME_OWNER_CHANGED], @@ -316,326 +303,219 @@ _dbus_hello (BusDBusImpl *dbus, name, "", name); - } - - return reply_message; } -static IBusMessage * -_dbus_list_names (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) +static void +bus_dbus_impl_list_names (BusDBusImpl *dbus, + BusConnection *connection, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply_message; - IBusMessageIter iter, sub_iter; - GList *name, *names; - gchar *v; - - reply_message = ibus_message_new_method_return (message); - - ibus_message_iter_init_append (reply_message, &iter); - ibus_message_iter_open_container (&iter, IBUS_TYPE_ARRAY, "s", &sub_iter); + GVariantBuilder builder; + g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); - v = DBUS_SERVICE_DBUS; - ibus_message_iter_append (&sub_iter, G_TYPE_STRING, &v); - - v = IBUS_SERVICE_IBUS; - ibus_message_iter_append (&sub_iter, G_TYPE_STRING, &v); + /* FIXME should add them? */ + g_variant_builder_add (&builder, "s", "org.freedesktop.DBus"); + g_variant_builder_add (&builder, "s", "org.freedesktop.IBus"); // append well-known names + GList *names, *name; names = g_hash_table_get_keys (dbus->names); names = g_list_sort (names, (GCompareFunc) g_strcmp0); for (name = names; name != NULL; name = name->next) { - ibus_message_iter_append (&sub_iter, G_TYPE_STRING, &(name->data)); + g_variant_builder_add (&builder, "s", name->data); } g_list_free (names); // append unique names names = g_hash_table_get_keys (dbus->unique_names); - names = g_list_sort (names, (GCompareFunc) g_strcmp0); for (name = names; name != NULL; name = name->next) { - ibus_message_iter_append (&sub_iter, G_TYPE_STRING, &(name->data)); + g_variant_builder_add (&builder, "s", name->data); } g_list_free (names); - ibus_message_iter_close_container (&iter, &sub_iter); - - return reply_message; + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(as)", &builder)); } -static IBusMessage * -_dbus_name_has_owner (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) +static void +bus_dbus_impl_name_has_owner (BusDBusImpl *dbus, + BusConnection *connection, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - gchar *name; - gboolean retval; - gboolean has_owner; - IBusMessage *reply_message; - IBusError *error; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &name, - G_TYPE_INVALID); - - if (! retval) { - reply_message = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply_message; - } + const gchar *name = NULL; + g_variant_get (parameters, "(&s)", &name); + gboolean has_owner; if (name[0] == ':') { has_owner = g_hash_table_lookup (dbus->unique_names, name) != NULL; } else { - has_owner = g_hash_table_lookup (dbus->names, name) != NULL; + if (g_strcmp0 (name, "org.freedesktop.DBus") == 0 || + g_strcmp0 (name, "org.freedesktop.IBus") == 0) + has_owner = TRUE; + else + has_owner = g_hash_table_lookup (dbus->names, name) != NULL; } - - reply_message = ibus_message_new_method_return (message); - ibus_message_append_args (reply_message, - G_TYPE_BOOLEAN, &has_owner, - G_TYPE_INVALID); - - return reply_message; + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(b)", has_owner)); } - -static IBusMessage * -_dbus_get_name_owner (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) +static void +bus_dbus_impl_get_name_owner (BusDBusImpl *dbus, + BusConnection *connection, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - gchar *name; - BusConnection *owner; - gboolean retval; - const gchar *owner_name = NULL; - IBusMessage *reply_message; - IBusError *error; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &name, - G_TYPE_INVALID); - - if (! retval) { - reply_message = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply_message; - } + const gchar *name_owner = NULL; + const gchar *name = NULL; + g_variant_get (parameters, "(&s)", &name); - if (g_strcmp0 (name, DBUS_SERVICE_DBUS) == 0 || - g_strcmp0 (name, IBUS_SERVICE_IBUS) == 0) { - owner_name = name; + if (g_strcmp0 (name, "org.freedesktop.IBus") == 0 || + g_strcmp0 (name, "org.freedesktop.DBus") == 0) { + name_owner = "org.freedesktop.DBus"; } else { - owner = bus_dbus_impl_get_connection_by_name (dbus, name); + BusConnection *owner = bus_dbus_impl_get_connection_by_name (dbus, name); if (owner != NULL) { - owner_name = bus_connection_get_unique_name (owner); + name_owner = bus_connection_get_unique_name (owner); } } - if (owner_name != NULL) { - reply_message = ibus_message_new_method_return (message); - ibus_message_append_args (reply_message, - G_TYPE_STRING, &owner_name, - G_TYPE_INVALID); + if (name_owner == NULL) { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER, + "Can not get name owner of '%s': no suce name", name); } else { - reply_message = ibus_message_new_error_printf (message, - DBUS_ERROR_NAME_HAS_NO_OWNER, - "Name '%s' does have owner", - name); + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(s)", name_owner)); } - - return reply_message; } -static IBusMessage * -_dbus_get_id (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) -{ - IBusMessage *reply_message; - const gchar *name; - - name = bus_connection_get_unique_name (connection); - - if (name == NULL) { - reply_message = ibus_message_new_error (message, - DBUS_ERROR_FAILED, - "Can not GetId before Hello"); - return reply_message; - } - reply_message = ibus_message_new_method_return (message); - ibus_message_append_args (reply_message, - G_TYPE_STRING, &name, - G_TYPE_INVALID); - return reply_message; +static void +bus_dbus_impl_get_id (BusDBusImpl *dbus, + BusConnection *connection, + GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + /* FXIME */ + const gchar *uuid = "FXIME"; + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(s)", uuid)); } static void -_rule_destroy_cb (BusMatchRule *rule, - BusDBusImpl *dbus) +bus_dbus_impl_rule_destroy_cb (BusMatchRule *rule, + BusDBusImpl *dbus) { - g_assert (BUS_IS_MATCH_RULE (rule)); - g_assert (BUS_IS_DBUS_IMPL (dbus)); - dbus->rules = g_list_remove (dbus->rules, rule); g_object_unref (rule); } -static IBusMessage * -_dbus_add_match (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) +static void +bus_dbus_impl_add_match (BusDBusImpl *dbus, + BusConnection *connection, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply_message; - IBusError *error; - gboolean retval; - gchar *rule_text; - BusMatchRule *rule; - GList *link; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &rule_text, - G_TYPE_INVALID); - - if (!retval) { - reply_message = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply_message; - } - - rule = bus_match_rule_new (rule_text); + const gchar *rule_text = NULL; + g_variant_get (parameters, "(&s)", &rule_text); + BusMatchRule *rule = bus_match_rule_new (rule_text); if (rule == NULL) { - reply_message = ibus_message_new_error_printf (message, - DBUS_ERROR_MATCH_RULE_INVALID, - "Parse rule [%s] failed", - rule_text); - return reply_message; + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_MATCH_RULE_INVALID, + "Parse match rule [%s] failed", rule_text); + return; } - for (link = dbus->rules; link != NULL; link = link->next) { - if (bus_match_rule_is_equal (rule, BUS_MATCH_RULE (link->data))) { - bus_match_rule_add_recipient (BUS_MATCH_RULE (link->data), connection); + g_dbus_method_invocation_return_value (invocation, NULL); + GList *p; + for (p = dbus->rules; p != NULL; p = p->next) { + if (bus_match_rule_is_equal (rule, (BusMatchRule *)p->data)) { + bus_match_rule_add_recipient ((BusMatchRule *)p->data, connection); g_object_unref (rule); - rule = NULL; - break; + return; } } if (rule) { bus_match_rule_add_recipient (rule, connection); dbus->rules = g_list_append (dbus->rules, rule); - g_signal_connect (rule, "destroy", G_CALLBACK (_rule_destroy_cb), dbus); + g_signal_connect (rule, "destroy", G_CALLBACK (bus_dbus_impl_rule_destroy_cb), dbus); } - - reply_message = ibus_message_new_method_return (message); - return reply_message; } -static IBusMessage * -_dbus_remove_match (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) +static void +bus_dbus_impl_remove_match (BusDBusImpl *dbus, + BusConnection *connection, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply_message; - IBusError *error; - gchar *rule_text; - BusMatchRule *rule; - GList *link; - - if (!ibus_message_get_args (message, - &error, - G_TYPE_STRING, &rule_text, - G_TYPE_INVALID)) { - reply_message = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply_message; - } + const gchar *rule_text = NULL; + g_variant_get (parameters, "(&s)", &rule_text); - rule = bus_match_rule_new (rule_text); - - if (rule == NULL ) { - reply_message = ibus_message_new_error_printf (message, - DBUS_ERROR_MATCH_RULE_INVALID, - "Parse rule [%s] failed", - rule_text); - return reply_message; + BusMatchRule *rule = bus_match_rule_new (rule_text); + if (rule == NULL) { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_MATCH_RULE_INVALID, + "Parse match rule [%s] failed", rule_text); + return; } - for (link = dbus->rules; link != NULL; link = link->next) { - if (bus_match_rule_is_equal (rule, BUS_MATCH_RULE (link->data))) { - bus_match_rule_remove_recipient (BUS_MATCH_RULE (link->data), connection); + g_dbus_method_invocation_return_value (invocation, NULL); + GList *p; + for (p = dbus->rules; p != NULL; p = p->next) { + if (bus_match_rule_is_equal (rule, (BusMatchRule *)p->data)) { + bus_match_rule_remove_recipient ((BusMatchRule *)p->data, connection); break; } } - g_object_unref (rule); - - reply_message = ibus_message_new_method_return (message); - return reply_message; } -static IBusMessage * -_dbus_request_name (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) +static void +bus_dbus_impl_request_name (BusDBusImpl *dbus, + BusConnection *connection, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply_message; - IBusError *error; - gchar *name; - guint flags; - guint retval; + /* FIXME need to handle flags */ + const gchar *name = NULL; + guint flags = 0; + g_variant_get (parameters, "(&su)", &name, &flags); + + if (name[0] == ':' || !g_dbus_is_name (name)) { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, + "'%s' is not a legal service name.", name); + return; + } - if (!ibus_message_get_args (message, - &error, - G_TYPE_STRING, &name, - G_TYPE_UINT, &flags, - G_TYPE_INVALID)) { - reply_message = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply_message; + if (g_strcmp0 (name, "org.freedesktop.DBus") == 0 || + g_strcmp0 (name, "org.freedesktop.IBus") == 0) { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, + "Can not acquire the service name '%s', it is reserved by IBus", name); + return; } - if (g_strcmp0 (name, DBUS_SERVICE_DBUS) == 0 || - g_strcmp0 (name, IBUS_SERVICE_IBUS) == 0 || - g_hash_table_lookup (dbus->names, name) != NULL) { - reply_message = ibus_message_new_error_printf (message, - DBUS_ERROR_FAILED, - "Name %s has owner", - name); - return reply_message; + if (g_hash_table_lookup (dbus->names, name) != NULL) { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Service name '%s' already has an owner.", name); + return; } - retval = 1; + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(u)", 1)); g_hash_table_insert (dbus->names, (gpointer )bus_connection_add_name (connection, name), connection); - reply_message = ibus_message_new_method_return (message); - ibus_message_append_args (reply_message, - G_TYPE_UINT, &retval, - G_TYPE_INVALID); - - ibus_connection_send ((IBusConnection *) connection, reply_message); - ibus_message_unref (reply_message); - ibus_connection_flush ((IBusConnection *) connection); g_signal_emit (dbus, dbus_signals[NAME_OWNER_CHANGED], @@ -643,277 +523,348 @@ _dbus_request_name (BusDBusImpl *dbus, name, "", bus_connection_get_unique_name (connection)); - - return NULL; } -static IBusMessage * -_dbus_release_name (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *connection) +static void +bus_dbus_impl_release_name (BusDBusImpl *dbus, + BusConnection *connection, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply_message; - IBusError *error; - gchar *name; - guint retval; + const gchar *name= NULL; + g_variant_get (parameters, "(&s)", &name); - if (!ibus_message_get_args (message, - &error, - G_TYPE_STRING, &name, - G_TYPE_INVALID)) { - reply_message = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply_message; + if (name[0] == ':' || !g_dbus_is_name (name)) { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, + "'%s' is not a legal service name.", name); + return; } - reply_message = ibus_message_new_method_return (message); - if (bus_connection_remove_name (connection, name)) { - retval = 1; + if (g_strcmp0 (name, "org.freedesktop.DBus") == 0 || + g_strcmp0 (name, "org.freedesktop.IBus") == 0) { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, + "Service name '%s' is owned by bus.", name); + return; } - else { + + guint retval; + if (g_hash_table_lookup (dbus->names, name) == NULL) { retval = 2; } - - ibus_message_append_args (message, - G_TYPE_UINT, &retval, - G_TYPE_INVALID); - - return reply_message; + else { + if (bus_connection_remove_name (connection, name)) { + retval = 1; + } + else { + retval = 3; + } + } + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(u)", retval)); } - -static gboolean -bus_dbus_impl_ibus_message (BusDBusImpl *dbus, - BusConnection *connection, - IBusMessage *message) +static void +bus_dbus_impl_name_owner_changed (BusDBusImpl *dbus, + gchar *name, + gchar *old_owner, + gchar *new_owner) { g_assert (BUS_IS_DBUS_IMPL (dbus)); - g_assert (BUS_IS_CONNECTION (connection)); - g_assert (message != NULL); + g_assert (name != NULL); + g_assert (old_owner != NULL); + g_assert (new_owner != NULL); + + GDBusMessage *message = g_dbus_message_new_signal ("/org/freedesktop/DBus", + "org.freedesktop.DBus", + "NameOwnerChanged"); + g_dbus_message_set_sender (message, "org.freedesktop.DBus"); + g_dbus_message_set_body (message, + g_variant_new ("(sss)", name, old_owner, new_owner)); + bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL); + g_object_unref (message); +} - gint i; - IBusMessage *reply_message = NULL; +static void +bus_dbus_impl_service_method_call (IBusService *service, + GDBusConnection *dbus_connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + BusDBusImpl *dbus = BUS_DBUS_IMPL (service); + + if (g_strcmp0 (interface_name, "org.freedesktop.DBus") != 0) { + IBUS_SERVICE_CLASS (bus_dbus_impl_parent_class)->service_method_call ( + (IBusService *) dbus, + dbus_connection, + sender, + object_path, + interface_name, + method_name, + parameters, + invocation); + return; + } static const struct { - const gchar *interface; - const gchar *name; - IBusMessage *(* handler) (BusDBusImpl *, IBusMessage *, BusConnection *); - } handlers[] = { - /* Introspectable interface */ - { DBUS_INTERFACE_INTROSPECTABLE, - "Introspect", _dbus_introspect }, + const gchar *method_name; + void (* method) (BusDBusImpl *, BusConnection *, GVariant *, GDBusMethodInvocation *); + } methods[] = { /* DBus interface */ - { DBUS_INTERFACE_DBUS, "Hello", _dbus_hello }, - { DBUS_INTERFACE_DBUS, "ListNames", _dbus_list_names }, - { DBUS_INTERFACE_DBUS, "ListActivatableNames", - _dbus_no_implement }, - { DBUS_INTERFACE_DBUS, "NameHasOwner", - _dbus_name_has_owner }, - { DBUS_INTERFACE_DBUS, "StartServiceByName", - _dbus_no_implement }, - { DBUS_INTERFACE_DBUS, "GetNameOwner", - _dbus_get_name_owner }, - { DBUS_INTERFACE_DBUS, "GetConnectionUnixUser", - _dbus_no_implement }, - { DBUS_INTERFACE_DBUS, "AddMatch", _dbus_add_match }, - { DBUS_INTERFACE_DBUS, "RemoveMatch", - _dbus_remove_match }, - { DBUS_INTERFACE_DBUS, "GetId", _dbus_get_id }, - { DBUS_INTERFACE_DBUS, "RequestName", _dbus_request_name }, - { DBUS_INTERFACE_DBUS, "ReleaseName", _dbus_release_name }, - { NULL, NULL, NULL } + { "Hello", bus_dbus_impl_hello }, + { "ListNames", bus_dbus_impl_list_names }, + { "NameHasOwner", bus_dbus_impl_name_has_owner }, + { "GetNameOwner", bus_dbus_impl_get_name_owner }, + { "GetId", bus_dbus_impl_get_id }, + { "AddMatch", bus_dbus_impl_add_match }, + { "RemoveMatch", bus_dbus_impl_remove_match }, + { "RequestName", bus_dbus_impl_request_name }, + { "ReleaseName", bus_dbus_impl_release_name }, }; - ibus_message_set_destination (message, DBUS_SERVICE_DBUS); - - for (i = 0; handlers[i].interface != NULL; i++) { - if (ibus_message_is_method_call (message, - handlers[i].interface, - handlers[i].name)) { - - reply_message = handlers[i].handler (dbus, message, connection); - if (reply_message) { - - ibus_message_set_sender (reply_message, DBUS_SERVICE_DBUS); - ibus_message_set_destination (reply_message, - bus_connection_get_unique_name (connection)); - ibus_message_set_no_reply (reply_message, TRUE); - - ibus_connection_send (IBUS_CONNECTION (connection), reply_message); - ibus_message_unref (reply_message); - } - - g_signal_stop_emission_by_name (dbus, "ibus-message"); - return TRUE; + gint i; + for (i = 0; i < G_N_ELEMENTS (methods); i++) { + if (g_strcmp0 (method_name, methods[i].method_name) == 0) { + BusConnection *connection = bus_connection_lookup (dbus_connection); + g_assert (BUS_IS_CONNECTION (connection)); + methods[i].method (dbus, connection, parameters, invocation); + return; } } - return IBUS_SERVICE_CLASS (bus_dbus_impl_parent_class)->ibus_message ( - (IBusService *) dbus, - (IBusConnection *) connection, - message); + /* unsupport methods */ + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, + "org.freedesktop.DBus does not support %s", method_name); } -static void -bus_dbus_impl_name_owner_changed (BusDBusImpl *dbus, - gchar *name, - gchar *old_name, - gchar *new_name) +static GVariant * +bus_dbus_impl_service_get_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error) { - g_assert (BUS_IS_DBUS_IMPL (dbus)); - g_assert (name != NULL); - g_assert (old_name != NULL); - g_assert (new_name != NULL); - - IBusMessage *message; - - message = ibus_message_new_signal (DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "NameOwnerChanged"); - ibus_message_append_args (message, - G_TYPE_STRING, &name, - G_TYPE_STRING, &old_name, - G_TYPE_STRING, &new_name, - G_TYPE_INVALID); - ibus_message_set_sender (message, DBUS_SERVICE_DBUS); - - bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL); - - ibus_message_unref (message); - + return IBUS_SERVICE_CLASS (bus_dbus_impl_parent_class)-> + service_get_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + error); } static gboolean -_connection_ibus_message_cb (BusConnection *connection, - IBusMessage *message, - BusDBusImpl *dbus) +bus_dbus_impl_service_set_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error) { - g_assert (BUS_IS_CONNECTION (connection)); - g_assert (message != NULL); - g_assert (BUS_IS_DBUS_IMPL (dbus)); - - const gchar *dest; - - if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) { - return FALSE; - } - - if (ibus_message_is_signal (message, - DBUS_INTERFACE_LOCAL, - "Disconnected")) { - /* ignore signal from local interface */ - return FALSE; - } + return IBUS_SERVICE_CLASS (bus_dbus_impl_parent_class)-> + service_set_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + value, + error); - ibus_message_set_sender (message, bus_connection_get_unique_name (connection)); +} - switch (ibus_message_get_type (message)) { #if 1 - case DBUS_MESSAGE_TYPE_ERROR: - g_debug ("From :%s to %s, Error: %s : %s", - ibus_message_get_sender (message), - ibus_message_get_destination (message), - ibus_message_get_error_name (message), - ibus_message_get_error_message (message)); +static void +message_print(GDBusMessage *message) +{ + switch (g_dbus_message_get_message_type (message)) { + case G_DBUS_MESSAGE_TYPE_METHOD_CALL: + g_debug ("From %s to %s, CALL(%u) %s.%s (%s)", + g_dbus_message_get_sender (message), + g_dbus_message_get_destination (message), + g_dbus_message_get_serial (message), + g_dbus_message_get_interface (message), + g_dbus_message_get_member (message), + g_dbus_message_get_signature (message) + ); break; -#endif -#if 0 - case DBUS_MESSAGE_TYPE_SIGNAL: - g_debug ("From :%s to %s, Signal: %s @ %s", - ibus_message_get_sender (message), - ibus_message_get_destination (message), - ibus_message_get_member (message), - ibus_message_get_path (message) - ); + case G_DBUS_MESSAGE_TYPE_METHOD_RETURN: + g_debug ("From %s to %s, RETURN(%u) (%s)", + g_dbus_message_get_sender (message), + g_dbus_message_get_destination (message), + g_dbus_message_get_reply_serial (message), + g_dbus_message_get_signature (message) + ); break; + case G_DBUS_MESSAGE_TYPE_ERROR: + g_debug ("From %s to %s, ERROR(%u) %s", + g_dbus_message_get_sender (message), + g_dbus_message_get_destination (message), + g_dbus_message_get_reply_serial (message), + g_dbus_message_get_error_name (message) + ); + break; + case G_DBUS_MESSAGE_TYPE_SIGNAL: + g_debug ("From %s to %s, SIGNAL %s.%s (%s) @ %s", + g_dbus_message_get_sender (message), + g_dbus_message_get_destination (message), + g_dbus_message_get_interface (message), + g_dbus_message_get_member (message), + g_dbus_message_get_signature (message), + g_dbus_message_get_path (message) + ); + break; + default: + break; + } + +} #endif + +static GDBusMessage * +bus_dbus_impl_connection_filter_cb (GDBusConnection *dbus_connection, + GDBusMessage *message, + gboolean incoming, + gpointer user_data) +{ #if 0 - case DBUS_MESSAGE_TYPE_METHOD_CALL: - g_debug("From %s to %s, Method %s on %s", - ibus_message_get_sender (message), - ibus_message_get_destination (message), - ibus_message_get_path (message), - ibus_message_get_member (message)); - break; + gchar *str = g_dbus_message_print (message, 4); + g_debug ("message: incoming=%d locked=%d \n%s", incoming, g_dbus_message_get_locked (message), str); + g_free (str); #endif - } - dest = ibus_message_get_destination (message); - - if (dest == NULL || - strcmp ((gchar *)dest, IBUS_SERVICE_IBUS) == 0 || - strcmp ((gchar *)dest, DBUS_SERVICE_DBUS) == 0) { - /* this message is sent to ibus-daemon */ - - switch (ibus_message_get_type (message)) { - case DBUS_MESSAGE_TYPE_SIGNAL: - case DBUS_MESSAGE_TYPE_METHOD_RETURN: - case DBUS_MESSAGE_TYPE_ERROR: - bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL); - return FALSE; - case DBUS_MESSAGE_TYPE_METHOD_CALL: - { - const gchar *path; - IBusService *object; - - path = ibus_message_get_path (message); - - object = g_hash_table_lookup (dbus->objects, path); - - if (object == NULL || - ibus_service_handle_message (object, - (IBusConnection *) connection, - message) == FALSE) { - IBusMessage *error; - error = ibus_message_new_error_printf (message, - DBUS_ERROR_UNKNOWN_METHOD, - "Unknown method %s on %s", - ibus_message_get_member (message), - path); - ibus_connection_send ((IBusConnection *) connection, error); - ibus_message_unref (error); - } - - /* dispatch message */ + g_assert (G_IS_DBUS_CONNECTION (dbus_connection)); + g_assert (G_IS_DBUS_MESSAGE (message)); + g_assert (BUS_IS_DBUS_IMPL (user_data)); + + BusDBusImpl *dbus = (BusDBusImpl *) user_data; + BusConnection *connection = bus_connection_lookup (dbus_connection); + g_assert (connection != NULL); + + if (incoming) { + /* is incoming message */ + const gchar *destination = g_dbus_message_get_destination (message); + GDBusMessageType message_type = g_dbus_message_get_message_type (message); + + if (g_dbus_message_get_locked (message)) { + /* If the message is locked, we need make a copy of it. */ + GDBusMessage *new_message = g_dbus_message_copy (message, NULL); + g_assert (new_message != NULL); + g_object_unref (message); + message = new_message; + } + + /* connection unique name as sender of the message*/ + g_dbus_message_set_sender (message, bus_connection_get_unique_name (connection)); + + if (g_strcmp0 (destination, "org.freedesktop.IBus") == 0) { + /* the message is sended to IBus service. */ + switch (message_type) { + case G_DBUS_MESSAGE_TYPE_METHOD_CALL: + case G_DBUS_MESSAGE_TYPE_METHOD_RETURN: + case G_DBUS_MESSAGE_TYPE_ERROR: + /* dispatch signal messages by match rule */ + bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL); + return message; + case G_DBUS_MESSAGE_TYPE_SIGNAL: + default: + /* dispatch signal messages by match rule */ bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL); + message_print (message); + g_object_unref (message); + g_return_val_if_reached (NULL); } - break; - default: - g_assert (FALSE); + } + else if (g_strcmp0 (destination, "org.freedesktop.DBus") == 0) { + /* The message is sended to DBus service. */ + switch (message_type) { + case G_DBUS_MESSAGE_TYPE_METHOD_CALL: + case G_DBUS_MESSAGE_TYPE_METHOD_RETURN: + case G_DBUS_MESSAGE_TYPE_ERROR: + /* dispatch signal messages by match rule */ + bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL); + return message; + case G_DBUS_MESSAGE_TYPE_SIGNAL: + default: + /* dispatch signal messages by match rule */ + bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL); + message_print (message); + g_object_unref (message); + g_return_val_if_reached (NULL); + } + } + else if (destination == NULL) { + switch (message_type) { + case G_DBUS_MESSAGE_TYPE_SIGNAL: + /* dispatch signal messages by match rule */ + bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL); + return message; + case G_DBUS_MESSAGE_TYPE_METHOD_RETURN: + case G_DBUS_MESSAGE_TYPE_ERROR: + return message; + case G_DBUS_MESSAGE_TYPE_METHOD_CALL: + default: + /* dispatch signal messages by match rule */ + bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL); + message_print (message); + g_object_unref (message); + g_return_val_if_reached (NULL); + } + } + else { + /* forward message */ + bus_dbus_impl_forward_message (dbus, connection, message); + g_object_unref (message); + return NULL; } } else { - /* If the destination is not IBus or DBus, the message will be forwanded. */ - bus_dbus_impl_dispatch_message (dbus, message); + /* is outgoing message */ + if (g_dbus_message_get_sender (message) == NULL) { + if (g_dbus_message_get_locked (message)) { + GDBusMessage *new_message = g_dbus_message_copy (message, NULL); + g_assert (new_message != NULL); + g_object_unref (message); + message = new_message; + } + /* If the message is sending from ibus-daemon directly, + * we set the sender to org.freedesktop.DBus */ + g_dbus_message_set_sender (message, "org.freedesktop.DBus"); + } + + /* dispatch the outgoing message by rules. */ + bus_dbus_impl_dispatch_message_by_rule (dbus, message, connection); + return message; } - - g_signal_stop_emission_by_name (connection, "ibus-message"); - return TRUE; } -static void -_connection_ibus_message_sent_cb (BusConnection *connection, - IBusMessage *message, - BusDBusImpl *dbus) +BusDBusImpl * +bus_dbus_impl_get_default (void) { - bus_dbus_impl_dispatch_message_by_rule (dbus, message, connection); + static BusDBusImpl *dbus = NULL; + + if (dbus == NULL) { + dbus = (BusDBusImpl *) g_object_new (BUS_TYPE_DBUS_IMPL, + "object-path", "/org/freedesktop/DBus", + NULL); + } + + return dbus; } static void -_connection_destroy_cb (BusConnection *connection, - BusDBusImpl *dbus) +bus_dbus_impl_connection_destroy_cb (BusConnection *connection, + BusDBusImpl *dbus) { - g_assert (BUS_IS_CONNECTION (connection)); - g_assert (BUS_IS_DBUS_IMPL (dbus)); - - /* - ibus_service_remove_from_connection ( - IBUS_SERVICE (dbus), - IBUS_CONNECTION (connection)); - */ - const gchar *unique_name = bus_connection_get_unique_name (connection); if (unique_name != NULL) { g_hash_table_remove (dbus->unique_names, unique_name); @@ -926,7 +877,6 @@ _connection_destroy_cb (BusConnection *connection, } const GList *name = bus_connection_get_names (connection); - while (name != NULL) { g_hash_table_remove (dbus->names, name->data); g_signal_emit (dbus, @@ -944,32 +894,31 @@ _connection_destroy_cb (BusConnection *connection, gboolean -bus_dbus_impl_new_connection (BusDBusImpl *dbus, - BusConnection *connection) +bus_dbus_impl_new_connection (BusDBusImpl *dbus, + BusConnection *connection) { + g_debug ("new connection"); g_assert (BUS_IS_DBUS_IMPL (dbus)); g_assert (BUS_IS_CONNECTION (connection)); - g_assert (g_list_find (dbus->connections, connection) == NULL); g_object_ref_sink (connection); dbus->connections = g_list_append (dbus->connections, connection); - g_signal_connect (connection, - "ibus-message", - G_CALLBACK (_connection_ibus_message_cb), - dbus); - - g_signal_connect (connection, - "ibus-message-sent", - G_CALLBACK (_connection_ibus_message_sent_cb), - dbus); - + bus_connection_set_filter (connection, + bus_dbus_impl_connection_filter_cb, g_object_ref (dbus), g_object_unref); g_signal_connect (connection, "destroy", - G_CALLBACK (_connection_destroy_cb), + G_CALLBACK (bus_dbus_impl_connection_destroy_cb), dbus); + ibus_service_register ((IBusService *)dbus, + bus_connection_get_dbus_connection (connection), NULL); + GList *p; + for (p = dbus->objects; p != NULL; p = p->next) { + ibus_service_register ((IBusService *)p->data, + bus_connection_get_dbus_connection (connection), NULL); + } return TRUE; } @@ -981,110 +930,207 @@ bus_dbus_impl_get_connection_by_name (BusDBusImpl *dbus, g_assert (BUS_IS_DBUS_IMPL (dbus)); g_assert (name != NULL); - BusConnection *connection = NULL; - - if (name[0] == ':') { - connection = BUS_CONNECTION (g_hash_table_lookup ( - dbus->unique_names, - name)); + if (G_LIKELY (name[0] == ':')) { + return (BusConnection *)g_hash_table_lookup (dbus->unique_names, name); } else { - connection = BUS_CONNECTION (g_hash_table_lookup ( - dbus->names, - name)); + return (BusConnection *)g_hash_table_lookup (dbus->names, name); } - - return connection; } - -void -bus_dbus_impl_dispatch_message (BusDBusImpl *dbus, - IBusMessage *message) +static gboolean +bus_dbus_impl_forward_message_idle_cb (BusDBusImpl *dbus) { - g_assert (BUS_IS_DBUS_IMPL (dbus)); - g_assert (message != NULL); + g_return_val_if_fail (dbus->forward_queue != NULL, FALSE); - const gchar *destination; - BusConnection *dest_connection = NULL; + g_mutex_lock (dbus->forward_lock); + GDBusMessage *message = (GDBusMessage *)dbus->forward_queue->data; + dbus->forward_queue = g_list_delete_link (dbus->forward_queue, dbus->forward_queue); + gboolean has_message = (dbus->forward_queue != NULL); + g_mutex_unlock (dbus->forward_lock); - if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) { - return; + const gchar *destination = g_dbus_message_get_destination (message); + BusConnection *dest_connection = NULL; + if (destination != NULL) + dest_connection = bus_dbus_impl_get_connection_by_name (dbus, destination); + if (dest_connection != NULL) { + /* FIXME workaround for gdbus. gdbus can not set an empty body message with signature '()' */ + if (g_dbus_message_get_body (message) == NULL) + g_dbus_message_set_signature (message, NULL); + GError *error = NULL; + gboolean retval = g_dbus_connection_send_message ( + bus_connection_get_dbus_connection (dest_connection), + message, + G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL, + NULL, &error); + if (!retval) { + g_warning ("send error failed: %s.", error->message); + // message_print (message); + g_error_free (error); + } } - - destination = ibus_message_get_destination (message); - - if (destination != NULL) { - dest_connection = bus_dbus_impl_get_connection_by_name (dbus, destination); - - if (dest_connection != NULL) { - ibus_connection_send (IBUS_CONNECTION (dest_connection), message); + else { + /* FIXME can not get destination */ +#if 0 + if (g_dbus_message_get_message_type (message) == G_DBUS_MESSAGE_TYPE_METHOD_CALL) { + /* reply an error message, if the destination does not exist */ + GDBusMessage *reply_message = g_dbus_message_new_method_error (message, + "org.freedesktop.DBus.Error.ServiceUnknown", + "No service name is '%s'.", destination); + g_dbus_message_set_sender (reply_message, "org.freedesktop.DBus"); + g_dbus_message_set_destination (reply_message, bus_connection_get_unique_name (connection)); + g_dbus_connection_send_message (bus_connection_get_dbus_connection (connection), + reply_message, NULL, NULL); + g_object_unref (reply_message); } else { - IBusMessage *reply_message; - reply_message = ibus_message_new_error_printf (message, - DBUS_ERROR_SERVICE_UNKNOWN, - "Can not find service %s", - destination); - bus_dbus_impl_dispatch_message (dbus, reply_message); - ibus_message_unref (reply_message); + /* ignore other messages */ } +#endif } - - bus_dbus_impl_dispatch_message_by_rule (dbus, message, dest_connection); + g_object_unref (message); + return has_message; } void -bus_dbus_impl_dispatch_message_by_rule (BusDBusImpl *dbus, - IBusMessage *message, - BusConnection *skip_connection) +bus_dbus_impl_forward_message (BusDBusImpl *dbus, + BusConnection *connection, + GDBusMessage *message) { g_assert (BUS_IS_DBUS_IMPL (dbus)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (skip_connection) || skip_connection == NULL); + g_assert (BUS_IS_CONNECTION (connection)); + g_assert (G_IS_DBUS_MESSAGE (message)); - GList *recipients = NULL; - GList *link = NULL; + if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) + return; - static gint32 data_slot = -1; + g_mutex_lock (dbus->forward_lock); + gboolean is_running = (dbus->forward_queue != NULL); + dbus->forward_queue = g_list_append (dbus->forward_queue, g_object_ref (message)); + g_mutex_unlock (dbus->forward_lock); + if (!is_running) + g_idle_add_full (0, (GSourceFunc) bus_dbus_impl_forward_message_idle_cb, + g_object_ref (dbus), (GDestroyNotify) g_object_unref); +} - if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) { - return; +static BusDispatchData * +bus_dispatch_data_new (GDBusMessage *message, + BusConnection *skip_connection) +{ + BusDispatchData *data = g_slice_new (BusDispatchData); + + data->message = (GDBusMessage *) g_object_ref (message); + if (skip_connection) { + data->skip_connection = (BusConnection *) g_object_ref (skip_connection); + } + else { + data->skip_connection = NULL; } + return data; +} + +static void +bus_dispatch_data_free (BusDispatchData *data) +{ + g_object_unref (data->message); + if (data->skip_connection) + g_object_unref (data->skip_connection); + g_slice_free (BusDispatchData, data); +} - if (data_slot == -1) { - dbus_message_allocate_data_slot (&data_slot); +static gboolean +bus_dbus_impl_dispatch_message_by_rule_idle_cb (BusDBusImpl *dbus) +{ + g_return_val_if_fail (dbus->dispatch_queue != NULL, FALSE); + + if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) { + /* dbus was destryed */ + g_mutex_lock (dbus->dispatch_lock); + g_list_foreach (dbus->dispatch_queue, (GFunc)bus_dispatch_data_free, NULL); + g_list_free (dbus->dispatch_queue); + dbus->dispatch_queue = NULL; + g_mutex_unlock (dbus->dispatch_lock); + return FALSE; } - /* If this message has been dispatched by rule, it will be ignored. */ - if (dbus_message_get_data (message, data_slot) != NULL) - return; + /* remove fist node */ + g_mutex_lock (dbus->dispatch_lock); + BusDispatchData *data = (BusDispatchData *)dbus->dispatch_queue->data; + dbus->dispatch_queue = g_list_delete_link (dbus->dispatch_queue, dbus->dispatch_queue); + gboolean has_message = (dbus->dispatch_queue != NULL); + g_mutex_unlock (dbus->dispatch_lock); - dbus_message_set_data (message, data_slot, (gpointer) TRUE, NULL); + GList *link = NULL; + GList *recipients = NULL; + /* check each match rules, and get recipients */ for (link = dbus->rules; link != NULL; link = link->next) { - GList *list = bus_match_rule_get_recipients (BUS_MATCH_RULE (link->data), - message); + GList *list = bus_match_rule_get_recipients ((BusMatchRule *)link->data, + data->message); recipients = g_list_concat (recipients, list); } + /* send message to each recipients */ for (link = recipients; link != NULL; link = link->next) { - BusConnection *connection = BUS_CONNECTION (link->data); - if (connection != skip_connection) { - ibus_connection_send (IBUS_CONNECTION (connection), message); + BusConnection *connection = (BusConnection *)link->data; + if (G_LIKELY (connection != data->skip_connection)) { + g_dbus_connection_send_message (bus_connection_get_dbus_connection (connection), + data->message, + G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL, + NULL, NULL); } } g_list_free (recipients); + bus_dispatch_data_free (data); + + return has_message; } +void +bus_dbus_impl_dispatch_message_by_rule (BusDBusImpl *dbus, + GDBusMessage *message, + BusConnection *skip_connection) +{ + g_assert (BUS_IS_DBUS_IMPL (dbus)); + g_assert (message != NULL); + g_assert (skip_connection == NULL || BUS_IS_CONNECTION (skip_connection)); + + if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) { + return; + } + + static GQuark dispatched_quark = 0; + if (dispatched_quark == 0) { + dispatched_quark = g_quark_from_static_string ("DISPATCHED"); + } + + /* If this message has been dispatched by rule. */ + if (g_object_get_qdata ((GObject *)message, dispatched_quark) != NULL) + return; + g_object_set_qdata ((GObject *)message, dispatched_quark, GINT_TO_POINTER (1)); + + /* append dispatch data into the queue, and start idle task if necessary */ + g_mutex_lock (dbus->dispatch_lock); + gboolean is_running = (dbus->dispatch_queue != NULL); + dbus->dispatch_queue = g_list_append (dbus->dispatch_queue, + bus_dispatch_data_new (message, skip_connection)); + g_mutex_unlock (dbus->dispatch_lock); + if (!is_running) { + g_idle_add_full (0, + (GSourceFunc)bus_dbus_impl_dispatch_message_by_rule_idle_cb, + g_object_ref (dbus), + (GDestroyNotify)g_object_unref); + } +} static void -_object_destroy_cb (IBusService *object, - BusDBusImpl *dbus) +bus_dbus_impl_object_destroy_cb (IBusService *object, + BusDBusImpl *dbus) { bus_dbus_impl_unregister_object (dbus, object); } + gboolean bus_dbus_impl_register_object (BusDBusImpl *dbus, IBusService *object) @@ -1092,23 +1138,21 @@ bus_dbus_impl_register_object (BusDBusImpl *dbus, g_assert (BUS_IS_DBUS_IMPL (dbus)); g_assert (IBUS_IS_SERVICE (object)); - const gchar *path; - if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) { return FALSE; } - path = ibus_service_get_path (object); - - g_return_val_if_fail (path, FALSE); - - g_return_val_if_fail (g_hash_table_lookup (dbus->objects, path) == NULL, FALSE); - - g_object_ref_sink (object); - g_hash_table_insert (dbus->objects, (gpointer)path, object); - - g_signal_connect (object, "destroy", G_CALLBACK (_object_destroy_cb), dbus); + dbus->objects = g_list_prepend (dbus->objects, g_object_ref (object)); + g_signal_connect (object, "destroy", + G_CALLBACK (bus_dbus_impl_object_destroy_cb), dbus); + GList *p; + for (p = dbus->connections; p != NULL; p = p->next) { + GDBusConnection *connection = bus_connection_get_dbus_connection ((BusConnection *)p->data); + if (connection != ibus_service_get_connection ((IBusService *)object)) + ibus_service_register ((IBusService *)object, + bus_connection_get_dbus_connection ((BusConnection *)p->data), NULL); + } return TRUE; } @@ -1119,20 +1163,20 @@ bus_dbus_impl_unregister_object (BusDBusImpl *dbus, g_assert (BUS_IS_DBUS_IMPL (dbus)); g_assert (IBUS_IS_SERVICE (object)); - const gchar *path; - - if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) { + GList *p = g_list_find (dbus->objects, object); + if (p == NULL) return FALSE; - } - - path = ibus_service_get_path (object); - g_return_val_if_fail (path, FALSE); - g_return_val_if_fail (g_hash_table_lookup (dbus->objects, path) == object, FALSE); - - g_signal_handlers_disconnect_by_func (object, G_CALLBACK (_object_destroy_cb), dbus); - - g_hash_table_remove (dbus->objects, path); + g_signal_handlers_disconnect_by_func (object, + G_CALLBACK (bus_dbus_impl_object_destroy_cb), dbus); + dbus->objects = g_list_delete_link (dbus->objects, p); + if (!IBUS_OBJECT_DESTROYED (object)) { + GList *p; + for (p = dbus->connections; p != NULL; p = p->next) { + ibus_service_unregister ((IBusService *)object, + bus_connection_get_dbus_connection ((BusConnection *)p->data)); + } + } g_object_unref (object); return TRUE; diff --git a/bus/dbusimpl.h b/bus/dbusimpl.h index da332d0..6eb37a8 100644 --- a/bus/dbusimpl.h +++ b/bus/dbusimpl.h @@ -19,9 +19,10 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __DBUS_IMPL_H_ -#define __DBUS_IMPL_H_ +#ifndef __BUS_DBUS_IMPL_H_ +#define __BUS_DBUS_IMPL_H_ +#include #include #include "connection.h" @@ -51,27 +52,6 @@ G_BEGIN_DECLS typedef struct _BusDBusImpl BusDBusImpl; typedef struct _BusDBusImplClass BusDBusImplClass; -struct _BusDBusImpl { - IBusService parent; - /* instance members */ - GHashTable *unique_names; - GHashTable *names; - GHashTable *objects; - GList *connections; - GList *rules; - gint id; -}; - -struct _BusDBusImplClass { - IBusServiceClass parent; - - /* class members */ - void (* name_owner_changed) (BusDBusImpl *dbus, - gchar *name, - gchar *old_name, - gchar *new_name); -}; - GType bus_dbus_impl_get_type (void); BusDBusImpl *bus_dbus_impl_get_default (void); gboolean bus_dbus_impl_new_connection (BusDBusImpl *dbus, @@ -79,17 +59,18 @@ gboolean bus_dbus_impl_new_connection (BusDBusImpl *dbus, BusConnection *bus_dbus_impl_get_connection_by_name (BusDBusImpl *dbus, const gchar *name); -void bus_dbus_impl_dispatch_message (BusDBusImpl *dbus, - IBusMessage *message); +/* FIXME */ +void bus_dbus_impl_forward_message (BusDBusImpl *dbus, + BusConnection *connection, + GDBusMessage *message); void bus_dbus_impl_dispatch_message_by_rule (BusDBusImpl *dbus, - IBusMessage *message, + GDBusMessage *message, BusConnection *skip_connection); gboolean bus_dbus_impl_register_object (BusDBusImpl *dbus, IBusService *object); gboolean bus_dbus_impl_unregister_object(BusDBusImpl *dbus, IBusService *object); - G_END_DECLS #endif diff --git a/bus/engineproxy.c b/bus/engineproxy.c index e48920e..9529c99 100644 --- a/bus/engineproxy.c +++ b/bus/engineproxy.c @@ -19,13 +19,36 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include -#include -#include -#include "ibusimpl.h" #include "engineproxy.h" +#include "types.h" +#include "marshalers.h" +#include "ibusimpl.h" #include "option.h" +struct _BusEngineProxy { + IBusProxy parent; + /* instance members */ + gboolean has_focus; + gboolean enabled; + guint capabilities; + /* cursor location */ + gint x; + gint y; + gint w; + gint h; + + IBusEngineDesc *desc; + IBusKeymap *keymap; + IBusPropList *prop_list; + + /* private member */ +}; + +struct _BusEngineProxyClass { + IBusProxyClass parent; + /* class members */ +}; + enum { COMMIT_TEXT, FORWARD_KEY_EVENT, @@ -48,60 +71,24 @@ enum { LAST_SIGNAL, }; - static guint engine_signals[LAST_SIGNAL] = { 0 }; // static guint engine_signals[LAST_SIGNAL] = { 0 }; /* functions prototype */ -static void bus_engine_proxy_real_destroy (BusEngineProxy *engine); +static void bus_engine_proxy_real_destroy (IBusProxy *proxy); -static gboolean bus_engine_proxy_ibus_signal (IBusProxy *proxy, - IBusMessage *message); +static void bus_engine_proxy_g_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters); G_DEFINE_TYPE (BusEngineProxy, bus_engine_proxy, IBUS_TYPE_PROXY) -BusEngineProxy * -bus_engine_proxy_new (const gchar *path, - IBusEngineDesc *desc, - BusConnection *connection) -{ - g_assert (path); - g_assert (IBUS_IS_ENGINE_DESC (desc)); - g_assert (BUS_IS_CONNECTION (connection)); - - BusEngineProxy *engine; - - engine = (BusEngineProxy *) g_object_new (BUS_TYPE_ENGINE_PROXY, - "name", NULL, - "path", path, - "connection", connection, - NULL); - - engine->desc = desc; - g_object_ref_sink (desc); - if (desc->layout != NULL && desc->layout[0] != '\0') { - engine->keymap = ibus_keymap_get (desc->layout); - } - - if (engine->keymap == NULL) { - engine->keymap = ibus_keymap_get ("us"); - } - - return engine; -} - static void bus_engine_proxy_class_init (BusEngineProxyClass *klass) { - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - IBusProxyClass *proxy_class = IBUS_PROXY_CLASS (klass); - - - bus_engine_proxy_parent_class = (IBusProxyClass *) g_type_class_peek_parent (klass); - - ibus_object_class->destroy = (IBusObjectDestroyFunc) bus_engine_proxy_real_destroy; - - proxy_class->ibus_signal = bus_engine_proxy_ibus_signal; + IBUS_PROXY_CLASS (klass)->destroy = bus_engine_proxy_real_destroy; + G_DBUS_PROXY_CLASS (klass)->g_signal = bus_engine_proxy_g_signal; /* install signals */ engine_signals[COMMIT_TEXT] = @@ -110,7 +97,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT, + bus_marshal_VOID__OBJECT, G_TYPE_NONE, 1, IBUS_TYPE_TEXT); @@ -121,7 +108,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__UINT_UINT_UINT, + bus_marshal_VOID__UINT_UINT_UINT, G_TYPE_NONE, 3, G_TYPE_UINT, @@ -134,7 +121,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__INT_UINT, + bus_marshal_VOID__INT_UINT, G_TYPE_NONE, 2, G_TYPE_INT, @@ -146,7 +133,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT_UINT_BOOLEAN_UINT, + bus_marshal_VOID__OBJECT_UINT_BOOLEAN_UINT, G_TYPE_NONE, 4, IBUS_TYPE_TEXT, @@ -160,7 +147,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -170,7 +157,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -180,7 +167,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT_BOOLEAN, + bus_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, IBUS_TYPE_TEXT, @@ -192,7 +179,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -202,7 +189,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -212,7 +199,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__BOXED_BOOLEAN, + bus_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, IBUS_TYPE_LOOKUP_TABLE, @@ -224,7 +211,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -234,7 +221,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -244,7 +231,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -254,7 +241,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -264,7 +251,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -274,7 +261,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -284,7 +271,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT, + bus_marshal_VOID__OBJECT, G_TYPE_NONE, 1, IBUS_TYPE_PROP_LIST); @@ -295,7 +282,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT, + bus_marshal_VOID__OBJECT, G_TYPE_NONE, 1, IBUS_TYPE_PROPERTY); @@ -305,25 +292,21 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) static void bus_engine_proxy_init (BusEngineProxy *engine) { - engine->has_focus = FALSE; - engine->enabled = FALSE; - engine->x = 0; - engine->y = 0; - engine->w = 0; - engine->h = 0; - engine->enabled = FALSE; - engine->desc = NULL; - engine->keymap = NULL; } static void -bus_engine_proxy_real_destroy (BusEngineProxy *engine) +bus_engine_proxy_real_destroy (IBusProxy *proxy) { - if (ibus_proxy_get_connection ((IBusProxy *) engine)) { - ibus_proxy_call ((IBusProxy *) engine, - "Destroy", - G_TYPE_INVALID); - } + BusEngineProxy *engine = (BusEngineProxy *)proxy; + + g_dbus_proxy_call ((GDBusProxy *)proxy, + "org.freedesktop.IBus.Service.Destroy", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); if (engine->desc) { g_object_unref (engine->desc); @@ -335,26 +318,27 @@ bus_engine_proxy_real_destroy (BusEngineProxy *engine) engine->keymap = NULL; } - IBUS_OBJECT_CLASS(bus_engine_proxy_parent_class)->destroy (IBUS_OBJECT (engine)); + IBUS_PROXY_CLASS(bus_engine_proxy_parent_class)->destroy ((IBusProxy *)engine); } -static gboolean -bus_engine_proxy_ibus_signal (IBusProxy *proxy, - IBusMessage *message) +static void +_g_object_unref_if_floating (gpointer instance) { - g_assert (BUS_IS_ENGINE_PROXY (proxy)); - g_assert (message != NULL); - g_assert (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_SIGNAL); - - const gchar *interface; - const gchar *name; - BusEngineProxy *engine; - IBusError *error; - gint i; + if (g_object_is_floating (instance)) + g_object_unref (instance); +} + +static void +bus_engine_proxy_g_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters) +{ + BusEngineProxy *engine = (BusEngineProxy *)proxy; static const struct { - const gchar *member; - const guint signal_id; + const gchar *signal_name; + const guint signal_id; } signals [] = { { "ShowPreeditText", SHOW_PREEDIT_TEXT }, { "HidePreeditText", HIDE_PREEDIT_TEXT }, @@ -368,48 +352,31 @@ bus_engine_proxy_ibus_signal (IBusProxy *proxy, { "CursorDownLookupTable", CURSOR_DOWN_LOOKUP_TABLE }, }; - engine = BUS_ENGINE_PROXY (proxy); - interface = ibus_message_get_interface (message); - name = ibus_message_get_member (message); - - if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_ENGINE) != 0) - return FALSE; - + gint i; for (i = 0; i < G_N_ELEMENTS (signals); i++) { - if (g_strcmp0 (name, signals[i].member) == 0) { + if (g_strcmp0 (signal_name, signals[i].signal_name) == 0) { g_signal_emit (engine, engine_signals[signals[i].signal_id], 0); - goto handled; + return; } } - if (g_strcmp0 (name, "CommitText") == 0) { - IBusText *text; - gboolean retval; + if (g_strcmp0 (signal_name, "CommitText") == 0) { + GVariant *arg0 = NULL; + g_variant_get(parameters, "(v)", &arg0); + g_return_if_fail (arg0 != NULL); - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_TEXT, &text, - G_TYPE_INVALID); - if (!retval) - goto failed; + IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (arg0)); + g_variant_unref (arg0); + g_return_if_fail (text != NULL); g_signal_emit (engine, engine_signals[COMMIT_TEXT], 0, text); - g_object_unref (text); + _g_object_unref_if_floating (text); } - else if (g_strcmp0 (name, "ForwardKeyEvent") == 0) { - guint32 keyval; - guint32 keycode; - guint32 states; - gboolean retval; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_UINT, &keyval, - G_TYPE_UINT, &keycode, - G_TYPE_UINT, &states, - G_TYPE_INVALID); - - if (!retval) - goto failed; + else if (g_strcmp0 (signal_name, "ForwardKeyEvent") == 0) { + guint32 keyval = 0; + guint32 keycode = 0; + guint32 states = 0; + g_variant_get (parameters, "(uuu)", &keyval, &keycode, &states); + g_signal_emit (engine, engine_signals[FORWARD_KEY_EVENT], 0, @@ -417,239 +384,151 @@ bus_engine_proxy_ibus_signal (IBusProxy *proxy, keycode, states); } - 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) - goto failed; - g_signal_emit (engine, engine_signals[DELETE_SURROUNDING_TEXT], 0, offset_from_cursor, nchars); + else if (g_strcmp0 (signal_name, "DeleteSurroundingText") == 0) { + gint offset_from_cursor = 0; + guint nchars = 0; + g_variant_get (parameters, "(iu)", &offset_from_cursor, &nchars); + + g_signal_emit (engine, + engine_signals[DELETE_SURROUNDING_TEXT], + 0, offset_from_cursor, nchars); } - else if (g_strcmp0 (name, "UpdatePreeditText") == 0) { - IBusText *text; - gint cursor_pos; - gboolean visible; - gboolean retval; - guint mode; - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_TEXT, &text, - G_TYPE_UINT, &cursor_pos, - G_TYPE_BOOLEAN, &visible, - G_TYPE_UINT, &mode, - G_TYPE_INVALID); - - if (!retval) - goto failed; - - g_signal_emit (engine, engine_signals[UPDATE_PREEDIT_TEXT], 0, - text, cursor_pos, visible, mode); - if (g_object_is_floating (text)) - g_object_unref (text); + else if (g_strcmp0 (signal_name, "UpdatePreeditText") == 0) { + GVariant *arg0 = NULL; + guint cursor_pos = 0; + gboolean visible = FALSE; + guint mode = 0; + + g_variant_get (parameters, "(vubu)", &arg0, &cursor_pos, &visible, &mode); + g_return_if_fail (arg0 != NULL); + + IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (arg0)); + g_variant_unref (arg0); + g_return_if_fail (text != NULL); + + g_signal_emit (engine, + engine_signals[UPDATE_PREEDIT_TEXT], + 0, text, cursor_pos, visible, mode); + + _g_object_unref_if_floating (text); } - else if (g_strcmp0 (name, "UpdateAuxiliaryText") == 0) { - IBusText *text; - gboolean visible; - gboolean retval; + else if (g_strcmp0 (signal_name, "UpdateAuxiliaryText") == 0) { + GVariant *arg0 = NULL; + gboolean visible = FALSE; - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_TEXT, &text, - G_TYPE_BOOLEAN, &visible, - G_TYPE_INVALID); + g_variant_get (parameters, "(vb)", &arg0, &visible); + g_return_if_fail (arg0 != NULL); - if (!retval) - goto failed; + IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (arg0)); + g_variant_unref (arg0); + g_return_if_fail (text != NULL); g_signal_emit (engine, engine_signals[UPDATE_AUXILIARY_TEXT], 0, text, visible); - if (g_object_is_floating (text)) - g_object_unref (text); + _g_object_unref_if_floating (text); } - else if (g_strcmp0 (name, "UpdateLookupTable") == 0) { - IBusLookupTable *table; - gboolean visible; - gboolean retval; + else if (g_strcmp0 (signal_name, "UpdateLookupTable") == 0) { + GVariant *arg0 = NULL; + gboolean visible = FALSE; - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_LOOKUP_TABLE, &table, - G_TYPE_BOOLEAN, &visible, - G_TYPE_INVALID); + g_variant_get (parameters, "(vb)", &arg0, &visible); + g_return_if_fail (arg0 != NULL); - if (!retval) - goto failed; + IBusLookupTable *table = IBUS_LOOKUP_TABLE (ibus_serializable_deserialize (arg0)); + g_variant_unref (arg0); + g_return_if_fail (table != NULL); g_signal_emit (engine, engine_signals[UPDATE_LOOKUP_TABLE], 0, table, visible); - if (g_object_is_floating (table)) - g_object_unref (table); + _g_object_unref_if_floating (table); } - else if (g_strcmp0 (name, "RegisterProperties") == 0) { - gboolean retval; - IBusPropList *prop_list; - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_PROP_LIST, &prop_list, - G_TYPE_INVALID); - if (!retval) { - goto failed; - } - g_signal_emit (engine, engine_signals[REGISTER_PROPERTIES], 0, prop_list); + else if (g_strcmp0 (signal_name, "RegisterProperties") == 0) { + GVariant *arg0 = NULL; + g_variant_get (parameters, "(v)", &arg0); + g_return_if_fail (arg0 != NULL); - if (g_object_is_floating (prop_list)) - g_object_unref (prop_list); + IBusPropList *prop_list = IBUS_PROP_LIST (ibus_serializable_deserialize (arg0)); + g_variant_unref (arg0); + g_return_if_fail (prop_list != NULL); + g_signal_emit (engine, engine_signals[REGISTER_PROPERTIES], 0, prop_list); + _g_object_unref_if_floating (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); + else if (g_strcmp0 (signal_name, "UpdateProperty") == 0) { + GVariant *arg0 = NULL; + g_variant_get (parameters, "(v)", &arg0); + g_return_if_fail (arg0 != NULL); - if (!retval) - goto failed; + IBusProperty *prop = IBUS_PROPERTY (ibus_serializable_deserialize (arg0)); + g_variant_unref (arg0); + g_return_if_fail (prop != NULL); g_signal_emit (engine, engine_signals[UPDATE_PROPERTY], 0, prop); - if (g_object_is_floating (prop)) - g_object_unref (prop); + _g_object_unref_if_floating (prop); } else - return FALSE; - -handled: - g_signal_stop_emission_by_name (engine, "ibus-signal"); - return TRUE; - -failed: - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - return FALSE; + return G_DBUS_PROXY_CLASS (bus_engine_proxy_parent_class)->g_signal ( + proxy, sender_name, signal_name, parameters); } -typedef struct { - GFunc func; - gpointer user_data; - BusEngineProxy *engine; -} CallData; - -static void -bus_engine_proxy_process_key_event_reply_cb (IBusPendingCall *pending, - CallData *call_data) +BusEngineProxy * +bus_engine_proxy_new (const gchar *path, + IBusEngineDesc *desc, + BusConnection *connection) { - IBusMessage *reply_message; - IBusError *error; - gboolean retval = FALSE; - - reply_message = dbus_pending_call_steal_reply (pending); - - if (reply_message == NULL) { - /* reply timeout */ - IBusObject *connection; - connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)call_data->engine); - ibus_object_destroy (connection); - goto _out; - } - else if ((error = ibus_error_new_from_message (reply_message)) != NULL) { - if (g_strcmp0 (error->name, DBUS_ERROR_NO_REPLY) == 0) { - /* reply timeout */ - IBusObject *connection; - connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)call_data->engine); - if (connection) { - ibus_object_destroy (connection); - } - } - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - goto _out; - } + g_assert (path); + g_assert (IBUS_IS_ENGINE_DESC (desc)); + g_assert (BUS_IS_CONNECTION (connection)); - if (!ibus_message_get_args (reply_message, - &error, - G_TYPE_BOOLEAN, &retval, - G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - goto _out; + BusEngineProxy *engine = + (BusEngineProxy *) g_initable_new (BUS_TYPE_ENGINE_PROXY, + NULL, + NULL, + "g-connection", bus_connection_get_dbus_connection (connection), + "g-interface-name", IBUS_INTERFACE_ENGINE, + "g-object-path", path, + NULL); + if (engine == NULL) + return NULL; + + engine->desc = desc; + g_object_ref_sink (desc); + if (desc->layout != NULL && desc->layout[0] != '\0') { + engine->keymap = ibus_keymap_get (desc->layout); } -_out: - if (reply_message) { - ibus_message_unref (reply_message); + if (engine->keymap == NULL) { + engine->keymap = ibus_keymap_get ("us"); } - g_object_unref (call_data->engine); - call_data->func (GINT_TO_POINTER (retval), call_data->user_data); - g_slice_free (CallData, call_data); + return engine; } void -bus_engine_proxy_process_key_event (BusEngineProxy *engine, - guint keyval, - guint keycode, - guint state, - GFunc return_cb, - gpointer user_data) +bus_engine_proxy_process_key_event (BusEngineProxy *engine, + guint keyval, + guint keycode, + guint state, + GAsyncReadyCallback callback, + gpointer user_data) { g_assert (BUS_IS_ENGINE_PROXY (engine)); - g_assert (return_cb); - - IBusPendingCall *pending = NULL; - CallData *call_data; - IBusError *error; - gboolean retval; + /* FIXME */ +#if 0 if (keycode != 0 && !BUS_DEFAULT_IBUS->use_sys_layout && engine->keymap != NULL) { guint t = ibus_keymap_lookup_keysym (engine->keymap, keycode, state); if (t != IBUS_VoidSymbol) { keyval = t; } } - - retval = ibus_proxy_call_with_reply ((IBusProxy *) engine, - "ProcessKeyEvent", - &pending, - g_dbus_timeout, - &error, - G_TYPE_UINT, &keyval, - G_TYPE_UINT, &keycode, - G_TYPE_UINT, &state, - G_TYPE_INVALID); - if (!retval) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - return_cb (GINT_TO_POINTER (FALSE), user_data); - return; - } - - call_data = g_slice_new0 (CallData); - call_data->func = return_cb; - call_data->user_data = user_data; - g_object_ref (engine); - call_data->engine = engine; - - retval = ibus_pending_call_set_notify (pending, - (IBusPendingCallNotifyFunction) bus_engine_proxy_process_key_event_reply_cb, - call_data, - NULL); - ibus_pending_call_unref (pending); - - if (!retval) { - g_object_unref (call_data->engine); - g_slice_free (CallData, call_data); - g_warning ("%s : ProcessKeyEvent", DBUS_ERROR_NO_MEMORY); - return_cb (GINT_TO_POINTER (FALSE), user_data); - return; - } +#endif + + g_dbus_proxy_call ((GDBusProxy *)engine, + "ProcessKeyEvent", + g_variant_new ("(uuu)", keyval, keycode, state), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + callback, + user_data); } void @@ -666,13 +545,14 @@ bus_engine_proxy_set_cursor_location (BusEngineProxy *engine, engine->y = y; engine->w = w; engine->h = h; - ibus_proxy_call ((IBusProxy *) engine, - "SetCursorLocation", - G_TYPE_INT, &x, - G_TYPE_INT, &y, - G_TYPE_INT, &w, - G_TYPE_INT, &h, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)engine, + "SetCursorLocation", + g_variant_new ("(iiii)", x, y, w, h), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); } } @@ -684,10 +564,14 @@ bus_engine_proxy_set_capabilities (BusEngineProxy *engine, if (engine->capabilities != caps) { engine->capabilities = caps; - ibus_proxy_call ((IBusProxy *) engine, - "SetCapabilities", - G_TYPE_UINT, &caps, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)engine, + "SetCapabilities", + g_variant_new ("(u)", caps), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); } } @@ -699,11 +583,14 @@ bus_engine_proxy_property_activate (BusEngineProxy *engine, g_assert (BUS_IS_ENGINE_PROXY (engine)); g_assert (prop_name != NULL); - ibus_proxy_call ((IBusProxy *) engine, - "PropertyActivate", - G_TYPE_STRING, &prop_name, - G_TYPE_UINT, &prop_state, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)engine, + "PropertyActivate", + g_variant_new ("(su)", prop_name, prop_state), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); } void @@ -713,10 +600,14 @@ bus_engine_proxy_property_show (BusEngineProxy *engine, g_assert (BUS_IS_ENGINE_PROXY (engine)); g_assert (prop_name != NULL); - ibus_proxy_call ((IBusProxy *) engine, - "PropertyShow", - G_TYPE_STRING, &prop_name, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)engine, + "PropertyShow", + g_variant_new ("(s)", prop_name), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); } void bus_engine_proxy_property_hide (BusEngineProxy *engine, @@ -725,10 +616,14 @@ void bus_engine_proxy_property_hide (BusEngineProxy *engine, g_assert (BUS_IS_ENGINE_PROXY (engine)); g_assert (prop_name != NULL); - ibus_proxy_call ((IBusProxy *) engine, - "PropertyHide", - G_TYPE_STRING, &prop_name, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)engine, + "PropertyHide", + g_variant_new ("(s)", prop_name), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); } #define DEFINE_FUNCTION(Name, name) \ @@ -736,9 +631,11 @@ void bus_engine_proxy_property_hide (BusEngineProxy *engine, bus_engine_proxy_##name (BusEngineProxy *engine) \ { \ g_assert (BUS_IS_ENGINE_PROXY (engine)); \ - ibus_proxy_call ((IBusProxy *) engine, \ - #Name, \ - G_TYPE_INVALID); \ + g_dbus_proxy_call ((GDBusProxy *)engine, \ + #Name, \ + NULL, \ + G_DBUS_CALL_FLAGS_NONE, \ + -1, NULL, NULL, NULL); \ } DEFINE_FUNCTION (Reset, reset) @@ -755,9 +652,14 @@ bus_engine_proxy_focus_in (BusEngineProxy *engine) g_assert (BUS_IS_ENGINE_PROXY (engine)); if (!engine->has_focus) { engine->has_focus = TRUE; - ibus_proxy_call ((IBusProxy *) engine, - "FocusIn", - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)engine, + "FocusIn", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); } } @@ -767,9 +669,14 @@ bus_engine_proxy_focus_out (BusEngineProxy *engine) g_assert (BUS_IS_ENGINE_PROXY (engine)); if (engine->has_focus) { engine->has_focus = FALSE; - ibus_proxy_call ((IBusProxy *) engine, - "FocusOut", - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)engine, + "FocusOut", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); } } @@ -779,9 +686,14 @@ bus_engine_proxy_enable (BusEngineProxy *engine) g_assert (BUS_IS_ENGINE_PROXY (engine)); if (!engine->enabled) { engine->enabled = TRUE; - ibus_proxy_call ((IBusProxy *) engine, - "Enable", - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)engine, + "Enable", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); } } @@ -791,9 +703,14 @@ bus_engine_proxy_disable (BusEngineProxy *engine) g_assert (BUS_IS_ENGINE_PROXY (engine)); if (engine->enabled) { engine->enabled = FALSE; - ibus_proxy_call ((IBusProxy *) engine, - "Disable", - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)engine, + "Disable", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); } } @@ -805,12 +722,14 @@ bus_engine_proxy_candidate_clicked (BusEngineProxy *engine, { g_assert (BUS_IS_ENGINE_PROXY (engine)); - ibus_proxy_call ((IBusProxy *) engine, - "CandidateClicked", - G_TYPE_UINT, &index, - G_TYPE_UINT, &button, - G_TYPE_UINT, &state, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)engine, + "CandidateClicked", + g_variant_new ("(uuu)", index, button, state), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); } IBusEngineDesc * diff --git a/bus/engineproxy.h b/bus/engineproxy.h index 254b00c..83c72da 100644 --- a/bus/engineproxy.h +++ b/bus/engineproxy.h @@ -19,9 +19,10 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __ENGINE_PROXY_H_ -#define __ENGINE_PROXY_H_ +#ifndef __BUS_ENGINE_PROXY_H_ +#define __BUS_ENGINE_PROXY_H_ +#include #include #include "connection.h" @@ -48,67 +49,43 @@ G_BEGIN_DECLS typedef struct _BusEngineProxy BusEngineProxy; typedef struct _BusEngineProxyClass BusEngineProxyClass; -struct _BusEngineProxy { - IBusProxy parent; - /* instance members */ - gboolean has_focus; - gboolean enabled; - guint capabilities; - /* cursor location */ - gint x; - gint y; - gint w; - gint h; - - IBusEngineDesc *desc; - IBusKeymap *keymap; - IBusPropList *prop_list; - - /* private member */ -}; - -struct _BusEngineProxyClass { - IBusProxyClass parent; - /* class members */ -}; - GType bus_engine_proxy_get_type (void); -BusEngineProxy *bus_engine_proxy_new (const gchar *path, - IBusEngineDesc *desc, - BusConnection *connection); -IBusEngineDesc *bus_engine_proxy_get_desc (BusEngineProxy *engine); -void bus_engine_proxy_process_key_event (BusEngineProxy *engine, - guint keyval, - guint keycode, - guint state, - GFunc return_cn, - gpointer user_data); +BusEngineProxy *bus_engine_proxy_new (const gchar *path, + IBusEngineDesc *desc, + BusConnection *connection); +IBusEngineDesc *bus_engine_proxy_get_desc (BusEngineProxy *engine); +void bus_engine_proxy_process_key_event (BusEngineProxy *engine, + guint keyval, + guint keycode, + guint state, + GAsyncReadyCallback callback, + gpointer user_data); void bus_engine_proxy_set_cursor_location - (BusEngineProxy *engine, - gint x, - gint y, - gint w, - gint h); -void bus_engine_proxy_focus_in (BusEngineProxy *engine); -void bus_engine_proxy_focus_out (BusEngineProxy *engine); -void bus_engine_proxy_reset (BusEngineProxy *engine); -void bus_engine_proxy_set_capabilities (BusEngineProxy *engine, - guint caps); -void bus_engine_proxy_page_up (BusEngineProxy *engine); -void bus_engine_proxy_page_down (BusEngineProxy *engine); -void bus_engine_proxy_cursor_up (BusEngineProxy *engine); -void bus_engine_proxy_cursor_down (BusEngineProxy *engine); -void bus_engine_proxy_candidate_clicked (BusEngineProxy *engine, - guint index, - guint button, - guint state); -void bus_engine_proxy_enable (BusEngineProxy *engine); -void bus_engine_proxy_disable (BusEngineProxy *engine); -void bus_engine_proxy_property_activate (BusEngineProxy *engine, - const gchar *prop_name, - guint state); -void bus_engine_proxy_property_show (BusEngineProxy *engine, - const gchar *prop_name); + (BusEngineProxy *engine, + gint x, + gint y, + gint w, + gint h); +void bus_engine_proxy_focus_in (BusEngineProxy *engine); +void bus_engine_proxy_focus_out (BusEngineProxy *engine); +void bus_engine_proxy_reset (BusEngineProxy *engine); +void bus_engine_proxy_set_capabilities (BusEngineProxy *engine, + guint caps); +void bus_engine_proxy_page_up (BusEngineProxy *engine); +void bus_engine_proxy_page_down (BusEngineProxy *engine); +void bus_engine_proxy_cursor_up (BusEngineProxy *engine); +void bus_engine_proxy_cursor_down (BusEngineProxy *engine); +void bus_engine_proxy_candidate_clicked (BusEngineProxy *engine, + guint index, + guint button, + guint state); +void bus_engine_proxy_enable (BusEngineProxy *engine); +void bus_engine_proxy_disable (BusEngineProxy *engine); +void bus_engine_proxy_property_activate (BusEngineProxy *engine, + const gchar *prop_name, + guint state); +void bus_engine_proxy_property_show (BusEngineProxy *engine, + const gchar *prop_name); void bus_engine_proxy_property_hide (BusEngineProxy *engine, const gchar *prop_name); gboolean bus_engine_proxy_is_enabled (BusEngineProxy *engine); diff --git a/bus/factoryproxy.c b/bus/factoryproxy.c index 1f413bf..9de44f5 100644 --- a/bus/factoryproxy.c +++ b/bus/factoryproxy.c @@ -19,18 +19,65 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include -#include -#include -#include "dbusimpl.h" #include "factoryproxy.h" +#include "types.h" +#include "marshalers.h" +#include "dbusimpl.h" #include "option.h" +struct _BusFactoryProxy { + IBusProxy parent; + /* instance members */ + + IBusComponent *component; + GList *engine_list; +}; + +struct _BusFactoryProxyClass { + IBusProxyClass parent; + /* class members */ +}; + /* functions prototype */ -static void bus_factory_proxy_destroy (BusFactoryProxy *factory); +static void bus_factory_proxy_destroy (IBusProxy *proxy); G_DEFINE_TYPE (BusFactoryProxy, bus_factory_proxy, IBUS_TYPE_PROXY) +static void +bus_factory_proxy_class_init (BusFactoryProxyClass *class) +{ + IBUS_PROXY_CLASS(class)->destroy = bus_factory_proxy_destroy; +} + +static void +bus_factory_proxy_init (BusFactoryProxy *factory) +{ + factory->component = NULL; +} + +static void +bus_factory_proxy_destroy (IBusProxy *proxy) +{ + BusFactoryProxy *factory = (BusFactoryProxy *)proxy; + GList *p; + + for (p = factory->engine_list; p != NULL ; p = p->next) { + IBusEngineDesc *desc = (IBusEngineDesc *)p->data; + g_object_steal_data ((GObject *)desc, "factory"); + g_object_unref (desc); + } + g_list_free (factory->engine_list); + factory->engine_list = NULL; + + if (factory->component) { + g_object_steal_data ((GObject *)factory->component, "factory"); + g_object_unref (factory->component); + factory->component = NULL; + } + + IBUS_PROXY_CLASS(bus_factory_proxy_parent_class)->destroy (IBUS_PROXY (factory)); +} + BusFactoryProxy * bus_factory_proxy_new (IBusComponent *component, BusConnection *connection) @@ -49,9 +96,9 @@ bus_factory_proxy_new (IBusComponent *component, } factory = g_object_new (BUS_TYPE_FACTORY_PROXY, - "name", NULL, - "path", "/org/freedesktop/IBus/Factory", - "connection", connection, + "g-object-path", "/org/freedesktop/IBus/Factory", + "g-interface-name", "org.freedesktop.IBus.Factory", + "g-connection", bus_connection_get_dbus_connection (connection), NULL); g_object_ref_sink (component); @@ -69,42 +116,6 @@ bus_factory_proxy_new (IBusComponent *component, return factory; } -static void -bus_factory_proxy_class_init (BusFactoryProxyClass *klass) -{ - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - - ibus_object_class->destroy = (IBusObjectDestroyFunc) bus_factory_proxy_destroy; -} - -static void -bus_factory_proxy_init (BusFactoryProxy *factory) -{ - factory->component = NULL; -} - -static void -bus_factory_proxy_destroy (BusFactoryProxy *factory) -{ - GList *p; - - for (p = factory->engine_list; p != NULL ; p = p->next) { - IBusEngineDesc *desc = (IBusEngineDesc *)p->data; - g_object_steal_data ((GObject *)desc, "factory"); - g_object_unref (desc); - } - g_list_free (factory->engine_list); - factory->engine_list = NULL; - - if (factory->component) { - g_object_steal_data ((GObject *)factory->component, "factory"); - g_object_unref (factory->component); - factory->component = NULL; - } - - IBUS_OBJECT_CLASS(bus_factory_proxy_parent_class)->destroy (IBUS_OBJECT (factory)); -} - IBusComponent * bus_factory_proxy_get_component (BusFactoryProxy *factory) { @@ -143,71 +154,28 @@ bus_factory_proxy_create_engine (BusFactoryProxy *factory, g_assert (BUS_IS_FACTORY_PROXY (factory)); g_assert (IBUS_IS_ENGINE_DESC (desc)); - IBusPendingCall *pending = NULL; - IBusMessage *reply_message; - IBusError *error; - BusEngineProxy *engine; - gchar *object_path; - gboolean retval; - if (g_list_find (factory->component->engines, desc) == NULL) { return NULL; } - retval = ibus_proxy_call_with_reply ((IBusProxy *) factory, - "CreateEngine", - &pending, - g_dbus_timeout, - &error, - G_TYPE_STRING, &(desc->name), - G_TYPE_INVALID); - - if (!retval) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); + GError *error = NULL; + GVariant *retval = g_dbus_proxy_call_sync ((GDBusProxy *)factory, + "CreateEngine", + g_variant_new ("(s)", desc->name), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (retval == NULL) { + g_warning ("Create engine failed. %s", error->message); + g_error_free (error); return NULL; } - ibus_pending_call_wait (pending); - reply_message = ibus_pending_call_steal_reply (pending); - ibus_pending_call_unref (pending); - - if (reply_message == NULL) { - IBusObject *connection; - connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)factory); - ibus_object_destroy (connection); - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - return NULL; - } - - if ((error = ibus_error_new_from_message (reply_message)) != NULL) { - if (g_strcmp0 (error->name, DBUS_ERROR_NO_REPLY) == 0) { - IBusObject *connection; - connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)factory); - ibus_object_destroy (connection); - } - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - ibus_message_unref (reply_message); - return NULL; - } - - if (!ibus_message_get_args (reply_message, - &error, - IBUS_TYPE_OBJECT_PATH, &object_path, - G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - ibus_message_unref (reply_message); - - return NULL; - } - - IBusConnection *connection = ibus_proxy_get_connection ((IBusProxy *) factory); - engine = bus_engine_proxy_new (object_path, desc, (BusConnection *) connection); - ibus_message_unref (reply_message); - + const gchar *object_path = NULL; + g_variant_get (retval, "(&o)", &object_path); + GDBusConnection *connection = g_dbus_proxy_get_connection ((GDBusProxy *) factory); + BusEngineProxy *engine = bus_engine_proxy_new (object_path, + desc, bus_connection_lookup (connection)); + g_variant_unref (retval); return engine; } diff --git a/bus/factoryproxy.h b/bus/factoryproxy.h index 4407459..2437be4 100644 --- a/bus/factoryproxy.h +++ b/bus/factoryproxy.h @@ -19,8 +19,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __FACTORY_PROXY_H_ -#define __FACTORY_PROXY_H_ +#ifndef __BUS_FACTORY_PROXY_H_ +#define __BUS_FACTORY_PROXY_H_ #include #include "connection.h" @@ -49,19 +49,6 @@ G_BEGIN_DECLS typedef struct _BusFactoryProxy BusFactoryProxy; typedef struct _BusFactoryProxyClass BusFactoryProxyClass; -struct _BusFactoryProxy { - IBusProxy parent; - /* instance members */ - - IBusComponent *component; - GList *engine_list; -}; - -struct _BusFactoryProxyClass { - IBusProxyClass parent; - /* class members */ -}; - GType bus_factory_proxy_get_type (void); BusFactoryProxy *bus_factory_proxy_new (IBusComponent *component, BusConnection *connection); diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c index da24354..5b1646b 100644 --- a/bus/ibusimpl.c +++ b/bus/ibusimpl.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include "types.h" #include "ibusimpl.h" #include "dbusimpl.h" #include "server.h" @@ -39,6 +39,43 @@ #include "inputcontext.h" #include "option.h" +struct _BusIBusImpl { + IBusService parent; + /* instance members */ + GHashTable *factory_dict; + GList *factory_list; + GList *contexts; + + GList *engine_list; + GList *register_engine_list; + GList *component_list; + + gboolean use_sys_layout; + gboolean embed_preedit_text; + gboolean enable_by_default; + + BusRegistry *registry; + + BusInputContext *focused_context; + BusPanelProxy *panel; + IBusConfig *config; + IBusHotkeyProfile *hotkey_profile; + IBusKeymap *keymap; + + gboolean use_global_engine; + BusEngineProxy *global_engine; + gchar *global_previous_engine_name; + + IBusHotkeyProfile *engines_hotkey_profile; + GHashTable *hotkey_to_engines_map; +}; + +struct _BusIBusImplClass { + IBusServiceClass parent; + + /* class members */ +}; + enum { LAST_SIGNAL, }; @@ -47,40 +84,67 @@ enum { PROP_0, }; -// static guint _signals[LAST_SIGNAL] = { 0 }; +/* +static guint _signals[LAST_SIGNAL] = { 0 }; +*/ /* functions prototype */ -static void bus_ibus_impl_destroy (BusIBusImpl *ibus); -static gboolean bus_ibus_impl_ibus_message (BusIBusImpl *ibus, - BusConnection *connection, - IBusMessage *message); +static void bus_ibus_impl_destroy (BusIBusImpl *ibus); +static void bus_ibus_impl_service_method_call + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation + *invocation); +/* FIXME */ +#if 0 +static GVariant *ibus_ibus_impl_service_get_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error); +static gboolean ibus_ibus_impl_service_set_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error); +#endif static void bus_ibus_impl_add_factory (BusIBusImpl *ibus, BusFactoryProxy *factory); static void bus_ibus_impl_set_trigger (BusIBusImpl *ibus, - GValue *value); + GVariant *value); static void bus_ibus_impl_set_next_engine_in_menu (BusIBusImpl *ibus, - GValue *value); + GVariant *value); static void bus_ibus_impl_set_previous_engine (BusIBusImpl *ibus, - GValue *value); - + GVariant *value); static void bus_ibus_impl_set_preload_engines (BusIBusImpl *ibus, - GValue *value); + GVariant *value); static void bus_ibus_impl_set_use_sys_layout (BusIBusImpl *ibus, - GValue *value); + GVariant *value); static void bus_ibus_impl_set_embed_preedit_text (BusIBusImpl *ibus, - GValue *value); + GVariant *value); static void bus_ibus_impl_set_enable_by_default (BusIBusImpl *ibus, - GValue *value); - + GVariant *value); static void bus_ibus_impl_set_use_global_engine (BusIBusImpl *ibus, - GValue *value); + GVariant *value); static void bus_ibus_impl_set_global_engine (BusIBusImpl *ibus, BusEngineProxy *engine); @@ -111,32 +175,67 @@ static void bus_ibus_impl_save_global_previous_engine_name_to_config static void bus_ibus_impl_update_engines_hotkey_profile (BusIBusImpl *ibus); -G_DEFINE_TYPE(BusIBusImpl, bus_ibus_impl, IBUS_TYPE_SERVICE) +static const gchar introspection_xml[] = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; -BusIBusImpl * -bus_ibus_impl_get_default (void) -{ - static BusIBusImpl *ibus = NULL; - if (ibus == NULL) { - ibus = (BusIBusImpl *) g_object_new (BUS_TYPE_IBUS_IMPL, - "path", IBUS_PATH_IBUS, - NULL); - bus_dbus_impl_register_object (BUS_DEFAULT_DBUS, - (IBusService *)ibus); - } - return ibus; -} +G_DEFINE_TYPE(BusIBusImpl, bus_ibus_impl, IBUS_TYPE_SERVICE) static void -bus_ibus_impl_class_init (BusIBusImplClass *klass) +bus_ibus_impl_class_init (BusIBusImplClass *class) { - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - - ibus_object_class->destroy = (IBusObjectDestroyFunc) bus_ibus_impl_destroy; - - IBUS_SERVICE_CLASS (klass)->ibus_message = (ServiceIBusMessageFunc) bus_ibus_impl_ibus_message; + IBUS_OBJECT_CLASS(class)->destroy = (IBusObjectDestroyFunc) bus_ibus_impl_destroy; + IBUS_SERVICE_CLASS (class)->service_method_call = bus_ibus_impl_service_method_call; + ibus_service_class_add_interfaces (IBUS_SERVICE_CLASS (class), introspection_xml); } static void @@ -155,42 +254,37 @@ _panel_destroy_cb (BusPanelProxy *panel, static void bus_ibus_impl_set_hotkey (BusIBusImpl *ibus, GQuark hotkey, - GValue *value) + GVariant *value) { g_assert (BUS_IS_IBUS_IMPL (ibus)); - GValueArray *array; - gint i; - ibus_hotkey_profile_remove_hotkey_by_event (ibus->hotkey_profile, hotkey); if (value == NULL) { return; } - g_return_if_fail (G_VALUE_TYPE (value) == G_TYPE_VALUE_ARRAY); - array = g_value_get_boxed (value); - - for (i = 0; i < array->n_values; i++) { - GValue *str; - - str = g_value_array_get_nth (array, i); - g_return_if_fail (G_VALUE_TYPE (str) == G_TYPE_STRING); - + GVariantIter iter; + g_variant_iter_init (&iter, value); + const gchar *str = NULL; + while (g_variant_iter_loop (&iter,"&s", &str)) { ibus_hotkey_profile_add_hotkey_from_string (ibus->hotkey_profile, - g_value_get_string (str), + str, hotkey); - } + } } static void bus_ibus_impl_set_trigger (BusIBusImpl *ibus, - GValue *value) + GVariant *value) { GQuark hotkey = g_quark_from_static_string ("trigger"); - bus_ibus_impl_set_hotkey (ibus, hotkey, value); - if (value == NULL) { + if (value != NULL) { + bus_ibus_impl_set_hotkey (ibus, hotkey, value); + } + else { + /* set defaint trigger */ ibus_hotkey_profile_add_hotkey (ibus->hotkey_profile, IBUS_space, IBUS_CONTROL_MASK, @@ -200,7 +294,7 @@ bus_ibus_impl_set_trigger (BusIBusImpl *ibus, static void bus_ibus_impl_set_next_engine_in_menu (BusIBusImpl *ibus, - GValue *value) + GVariant *value) { GQuark hotkey = g_quark_from_static_string ("next-engine-in-menu"); bus_ibus_impl_set_hotkey (ibus, hotkey, value); @@ -208,7 +302,7 @@ bus_ibus_impl_set_next_engine_in_menu (BusIBusImpl *ibus, static void bus_ibus_impl_set_previous_engine (BusIBusImpl *ibus, - GValue *value) + GVariant *value) { GQuark hotkey = g_quark_from_static_string ("previous-engine"); bus_ibus_impl_set_hotkey (ibus, hotkey, value); @@ -216,32 +310,21 @@ bus_ibus_impl_set_previous_engine (BusIBusImpl *ibus, static void bus_ibus_impl_set_preload_engines (BusIBusImpl *ibus, - GValue *value) + GVariant *value) { GList *engine_list = NULL; g_list_foreach (ibus->engine_list, (GFunc) g_object_unref, NULL); g_list_free (ibus->engine_list); - if (value != NULL && G_VALUE_TYPE (value) == G_TYPE_VALUE_ARRAY) { - GValueArray *array; - gint i; - - array = (GValueArray *) g_value_get_boxed (value); - for (i = 0; array && i < array->n_values; i++) { - const gchar *engine_name; - IBusEngineDesc *engine; - - if (G_VALUE_TYPE (&array->values[i]) != G_TYPE_STRING) - continue; - - engine_name = g_value_get_string (&array->values[i]); - - engine = bus_registry_find_engine_by_name (ibus->registry, engine_name); - + if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_ARRAY) { + GVariantIter iter; + g_variant_iter_init (&iter, value); + const gchar *engine_name = NULL; + while (g_variant_iter_loop (&iter, "&s", &engine_name)) { + IBusEngineDesc *engine = bus_registry_find_engine_by_name (ibus->registry, engine_name); if (engine == NULL || g_list_find (engine_list, engine) != NULL) continue; - engine_list = g_list_append (engine_list, engine); } } @@ -250,9 +333,7 @@ bus_ibus_impl_set_preload_engines (BusIBusImpl *ibus, ibus->engine_list = engine_list; if (ibus->engine_list) { - IBusComponent *component; - - component = ibus_component_get_from_engine ((IBusEngineDesc *) ibus->engine_list->data); + IBusComponent *component = ibus_component_get_from_engine ((IBusEngineDesc *) ibus->engine_list->data); if (component && !ibus_component_is_running (component)) { ibus_component_start (component, g_verbose); } @@ -263,53 +344,48 @@ bus_ibus_impl_set_preload_engines (BusIBusImpl *ibus, static void bus_ibus_impl_set_use_sys_layout (BusIBusImpl *ibus, - GValue *value) + GVariant *value) { - if (value != NULL && G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) { - ibus->use_sys_layout = g_value_get_boolean (value); + if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_BOOLEAN) { + ibus->use_sys_layout = g_variant_get_boolean (value); } } static void bus_ibus_impl_set_embed_preedit_text (BusIBusImpl *ibus, - GValue *value) + GVariant *value) { - if (value != NULL && G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) { - ibus->embed_preedit_text = g_value_get_boolean (value); + if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_BOOLEAN) { + ibus->embed_preedit_text = g_variant_get_boolean (value); } } static void bus_ibus_impl_set_enable_by_default (BusIBusImpl *ibus, - GValue *value) + GVariant *value) { - if (value != NULL && G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) { - ibus->enable_by_default = g_value_get_boolean (value); + if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_BOOLEAN) { + ibus->enable_by_default = g_variant_get_boolean (value); } } static void bus_ibus_impl_set_use_global_engine (BusIBusImpl *ibus, - GValue *value) + GVariant *value) { - gboolean new_value; - - if (value == NULL || G_VALUE_TYPE (value) != G_TYPE_BOOLEAN) { + if (value == NULL || g_variant_classify (value) != G_VARIANT_CLASS_BOOLEAN) return; - } - new_value = g_value_get_boolean (value); - if (ibus->use_global_engine == new_value) { + gboolean new_value = g_variant_get_boolean (value); + if (ibus->use_global_engine == new_value) return; - } - if (new_value == TRUE) { - BusEngineProxy *engine; + if (new_value) { /* turn on use_global_engine option */ ibus->use_global_engine = TRUE; - engine = ibus->focused_context != NULL ? + BusEngineProxy *engine = ibus->focused_context != NULL ? bus_input_context_get_engine (ibus->focused_context) : NULL; - if (engine) { + if (engine != NULL) { bus_ibus_impl_set_global_engine (ibus, engine); } } @@ -317,7 +393,6 @@ bus_ibus_impl_set_use_global_engine (BusIBusImpl *ibus, /* turn off use_global_engine option */ bus_ibus_impl_set_global_engine (ibus, NULL); ibus->use_global_engine = FALSE; - g_free (ibus->global_previous_engine_name); } } @@ -335,29 +410,26 @@ bus_ibus_impl_set_default_preload_engines (BusIBusImpl *ibus) g_assert (BUS_IS_IBUS_IMPL (ibus)); static gboolean done = FALSE; - GValue value = { 0 }; - GList *engines, *list; - gchar *lang, *p; - GValueArray *array; if (done || ibus->config == NULL) { return; } - if (ibus_config_get_value (ibus->config, "general", "preload_engines", &value)) { + GVariant *variant = ibus_config_get_value (ibus->config, "general", "preload_engines"); + if (variant != NULL) { done = TRUE; - g_value_unset (&value); + g_variant_unref (variant); return; } done = TRUE; - lang = g_strdup (setlocale (LC_ALL, NULL)); - p = index (lang, '.'); + gchar *lang = g_strdup (setlocale (LC_ALL, NULL)); + gchar *p = index (lang, '.'); if (p) { *p = '\0'; } - engines = bus_registry_get_engines_by_language (ibus->registry, lang); + GList *engines = bus_registry_get_engines_by_language (ibus->registry, lang); if (engines == NULL) { p = index (lang, '_'); if (p) { @@ -370,69 +442,49 @@ bus_ibus_impl_set_default_preload_engines (BusIBusImpl *ibus) /* sort engines by rank */ engines = g_list_sort (engines, (GCompareFunc) _engine_desc_cmp); - g_value_init (&value, G_TYPE_VALUE_ARRAY); - array = g_value_array_new (5); + GVariantBuilder builder; + g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); + GList *list; for (list = engines; list != NULL; list = list->next) { - IBusEngineDesc *desc; - GValue name = { 0 }; - desc = (IBusEngineDesc *)list->data; - + IBusEngineDesc *desc = (IBusEngineDesc *)list->data; /* ignore engines with rank <== 0 */ - if (desc->rank <= 0) - break; - g_value_init (&name, G_TYPE_STRING); - g_value_set_string (&name, desc->name); - g_value_array_append (array, &name); + if (desc->rank > 0) + g_variant_builder_add (&builder, "s", desc->name); } - g_value_take_boxed (&value, array); - ibus_config_set_value (ibus->config, "general", "preload_engines", &value); - g_value_unset (&value); + ibus_config_set_value (ibus->config, + "general", "preload_engines", g_variant_builder_end (&builder)); g_list_free (engines); } +const static struct { + gchar *section; + gchar *key; + void ( *func) (BusIBusImpl *, GVariant *); +} bus_ibus_impl_config_items [] = { + { "general/hotkey", "trigger", bus_ibus_impl_set_trigger }, + { "general/hotkey", "next_engine_in_menu", bus_ibus_impl_set_next_engine_in_menu }, + { "general/hotkey", "previous_engine", bus_ibus_impl_set_previous_engine }, + { "general", "preload_engines", bus_ibus_impl_set_preload_engines }, + { "general", "use_system_keyboard_layout", bus_ibus_impl_set_use_sys_layout }, + { "general", "use_global_engine", bus_ibus_impl_set_use_global_engine }, + { "general", "embed_preedit_text", bus_ibus_impl_set_embed_preedit_text }, + { "general", "enable_by_default", bus_ibus_impl_set_enable_by_default }, +}; + static void bus_ibus_impl_reload_config (BusIBusImpl *ibus) { g_assert (BUS_IS_IBUS_IMPL (ibus)); gint i; - GValue value = { 0 }; - - const static struct { - gchar *section; - gchar *key; - void ( *func) (BusIBusImpl *, GValue *); - } entries [] = { - { "general/hotkey", "trigger", bus_ibus_impl_set_trigger }, - #if 0 - /* Only for backward compatibility, shall be removed later. */ - { "general/hotkey", "next_engine", bus_ibus_impl_set_next_engine_in_menu }, - #endif - { "general/hotkey", "next_engine_in_menu", bus_ibus_impl_set_next_engine_in_menu }, - #if 0 - /* Only for backward compatibility, shall be removed later. */ - { "general/hotkey", "prev_engine", bus_ibus_impl_set_previous_engine }, - #endif - { "general/hotkey", "previous_engine", bus_ibus_impl_set_previous_engine }, - { "general", "preload_engines", bus_ibus_impl_set_preload_engines }, - { "general", "use_system_keyboard_layout", bus_ibus_impl_set_use_sys_layout }, - { "general", "use_global_engine", bus_ibus_impl_set_use_global_engine }, - { "general", "embed_preedit_text", bus_ibus_impl_set_embed_preedit_text }, - { "general", "enable_by_default", bus_ibus_impl_set_enable_by_default }, - }; - - for (i = 0; i < G_N_ELEMENTS (entries); i++) { - if (ibus->config != NULL && - ibus_config_get_value (ibus->config, - entries[i].section, - entries[i].key, - &value)) { - entries[i].func (ibus, &value); - g_value_unset (&value); - } - else { - entries[i].func (ibus, NULL); - } + for (i = 0; i < G_N_ELEMENTS (bus_ibus_impl_config_items); i++) { + GVariant *variant = NULL; + if (ibus->config != NULL) + variant = ibus_config_get_value (ibus->config, + bus_ibus_impl_config_items[i].section, + bus_ibus_impl_config_items[i].key); + bus_ibus_impl_config_items[i].func (ibus, variant); + if (variant) g_variant_unref (variant); } } @@ -440,7 +492,7 @@ static void _config_value_changed_cb (IBusConfig *config, gchar *section, gchar *key, - GValue *value, + GVariant *value, BusIBusImpl *ibus) { g_assert (IBUS_IS_CONFIG (config)); @@ -450,34 +502,10 @@ _config_value_changed_cb (IBusConfig *config, g_assert (BUS_IS_IBUS_IMPL (ibus)); gint i; - - const static struct { - gchar *section; - gchar *key; - void ( *func) (BusIBusImpl *, GValue *); - } entries [] = { - { "general/hotkey", "trigger", bus_ibus_impl_set_trigger }, - #if 0 - /* Only for backward compatibility, shall be removed later. */ - { "general/hotkey", "next_engine", bus_ibus_impl_set_next_engine_in_menu }, - #endif - { "general/hotkey", "next_engine_in_menu", bus_ibus_impl_set_next_engine_in_menu }, - #if 0 - /* Only for backward compatibility, shall be removed later. */ - { "general/hotkey", "prev_engine", bus_ibus_impl_set_previous_engine }, - #endif - { "general/hotkey", "previous_engine", bus_ibus_impl_set_previous_engine }, - { "general", "preload_engines", bus_ibus_impl_set_preload_engines }, - { "general", "use_system_keyboard_layout", bus_ibus_impl_set_use_sys_layout }, - { "general", "use_global_engine", bus_ibus_impl_set_use_global_engine }, - { "general", "embed_preedit_text", bus_ibus_impl_set_embed_preedit_text }, - { "general", "enable_by_default", bus_ibus_impl_set_enable_by_default }, - }; - - for (i = 0; i < G_N_ELEMENTS (entries); i++) { - if (g_strcmp0 (entries[i].section, section) == 0 && - g_strcmp0 (entries[i].key, key) == 0) { - entries[i].func (ibus, value); + for (i = 0; i < G_N_ELEMENTS (bus_ibus_impl_config_items); i++) { + if (g_strcmp0 (bus_ibus_impl_config_items[i].section, section) == 0 && + g_strcmp0 (bus_ibus_impl_config_items[i].key, key) == 0) { + bus_ibus_impl_config_items[i].func (ibus, value); break; } } @@ -523,7 +551,7 @@ _dbus_name_owner_changed_cb (BusDBusImpl *dbus, BusConnection *connection; if (ibus->panel != NULL) { - ibus_object_destroy (IBUS_OBJECT (ibus->panel)); + ibus_proxy_destroy ((IBusProxy *)ibus->panel); /* panel should be NULL after destroy */ g_assert (ibus->panel == NULL); } @@ -549,7 +577,7 @@ _dbus_name_owner_changed_cb (BusDBusImpl *dbus, BusConnection *connection; if (ibus->config != NULL) { - ibus_object_destroy (IBUS_OBJECT (ibus->config)); + ibus_proxy_destroy ((IBusProxy *)ibus->config); /* config should be NULL */ g_assert (ibus->config == NULL); } @@ -558,9 +586,9 @@ _dbus_name_owner_changed_cb (BusDBusImpl *dbus, g_return_if_fail (connection != NULL); ibus->config = g_object_new (IBUS_TYPE_CONFIG, - "name", NULL, - "path", IBUS_PATH_CONFIG, - "connection", connection, + "g-object-path", "/org/freedesktop/IBus/Config", + "g-interface-name", "org.freedesktop.IBus.Config", + "g-connection", bus_connection_get_dbus_connection (connection), NULL); g_object_ref_sink (ibus->config); @@ -715,101 +743,17 @@ bus_ibus_impl_destroy (BusIBusImpl *ibus) ibus->hotkey_to_engines_map = NULL; } - bus_server_quit (BUS_DEFAULT_SERVER); - ibus_object_destroy ((IBusObject *) BUS_DEFAULT_SERVER); + bus_server_quit (); IBUS_OBJECT_CLASS(bus_ibus_impl_parent_class)->destroy (IBUS_OBJECT (ibus)); } -/* introspectable interface */ -static IBusMessage * -_ibus_introspect (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) -{ - static const gchar *introspect = - DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - "\n"; - - IBusMessage *reply_message; - reply_message = ibus_message_new_method_return (message); - ibus_message_append_args (reply_message, - G_TYPE_STRING, &introspect, - G_TYPE_INVALID); - - return reply_message; -} - - - -static IBusMessage * -_ibus_get_address (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) -{ - const gchar *address; - IBusMessage *reply; - - address = ibus_server_get_address (IBUS_SERVER (BUS_DEFAULT_SERVER)); - - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - G_TYPE_STRING, &address, - G_TYPE_INVALID); - - return reply; +static void +_ibus_get_address (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + /* FIXME */ + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "FIXME")); } @@ -879,7 +823,7 @@ bus_ibus_impl_create_engine (IBusEngineDesc *engine_desc) static IBusEngineDesc * _find_engine_desc_by_name(BusIBusImpl *ibus, - gchar *engine_name) + const gchar *engine_name) { IBusEngineDesc *engine_desc = NULL; GList *p; @@ -903,7 +847,7 @@ _find_engine_desc_by_name(BusIBusImpl *ibus, static void _context_request_engine_cb (BusInputContext *context, - gchar *engine_name, + const gchar *engine_name, BusIBusImpl *ibus) { IBusEngineDesc *engine_desc = NULL; @@ -919,10 +863,10 @@ _context_request_engine_cb (BusInputContext *context, return; } else { - engine_name = bus_ibus_impl_load_global_engine_name_from_config (ibus); - if (engine_name) { - engine_desc = _find_engine_desc_by_name (ibus, engine_name); - g_free (engine_name); + gchar *name = bus_ibus_impl_load_global_engine_name_from_config (ibus); + if (name) { + engine_desc = _find_engine_desc_by_name (ibus, name); + g_free (name); } } } @@ -1043,12 +987,12 @@ bus_ibus_impl_set_global_engine (BusIBusImpl *ibus, /* Save the current global engine's name as previous engine. */ ibus->global_previous_engine_name = g_strdup (bus_engine_proxy_get_desc (ibus->global_engine)->name); - ibus_object_destroy ((IBusObject *)ibus->global_engine); + ibus_proxy_destroy ((IBusProxy *)ibus->global_engine); /* global_engine should be NULL */ g_assert (ibus->global_engine == NULL); } - if (engine != NULL && !IBUS_OBJECT_DESTROYED (engine)) { + if (engine != NULL && !IBUS_PROXY_DESTROYED (engine)) { g_object_ref (engine); ibus->global_engine = engine; g_signal_connect (ibus->global_engine, "destroy", @@ -1223,34 +1167,16 @@ _context_disabled_cb (BusInputContext *context, } #endif -static IBusMessage * -_ibus_create_input_context (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_create_input_context (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_IBUS_IMPL (ibus)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); + const gchar *client_name = NULL; + g_variant_get (parameters, "(&s)", &client_name); - gint i; - gchar *client; - IBusError *error; - IBusMessage *reply; - BusInputContext *context; - const gchar *path; - - if (!ibus_message_get_args (message, - &error, - G_TYPE_STRING, &client, - G_TYPE_INVALID)) { - reply = ibus_message_new_error (message, - DBUS_ERROR_INVALID_ARGS, - "Argument 1 of CreateInputContext should be an string"); - ibus_error_free (error); - return reply; - } - - context = bus_input_context_new (connection, client); + BusConnection *connection = bus_connection_lookup (g_dbus_method_invocation_get_connection (invocation)); + BusInputContext *context = bus_input_context_new (connection, client_name); g_object_ref_sink (context); ibus->contexts = g_list_append (ibus->contexts, context); @@ -1269,6 +1195,7 @@ _ibus_create_input_context (BusIBusImpl *ibus, #endif }; + gint i; for (i = 0; i < G_N_ELEMENTS (signals); i++) { g_signal_connect (context, signals[i].name, @@ -1280,44 +1207,26 @@ _ibus_create_input_context (BusIBusImpl *ibus, bus_input_context_enable (context); } - path = ibus_service_get_path ((IBusService *) context); - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - IBUS_TYPE_OBJECT_PATH, &path, - G_TYPE_INVALID); - + const gchar *path = ibus_service_get_object_path ((IBusService *) context); bus_dbus_impl_register_object (BUS_DEFAULT_DBUS, (IBusService *)context); - return reply; + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", path)); } -static IBusMessage * -_ibus_current_input_context (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_current_input_context (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_IBUS_IMPL (ibus)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - const gchar *path; - if (!ibus->focused_context) { - reply = ibus_message_new_error (message, - DBUS_ERROR_FAILED, - "No input context focused"); - return reply; + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "No focused input context"); + } + else { + const gchar *path = ibus_service_get_object_path ((IBusService *)ibus->focused_context); + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", path)); } - - reply = ibus_message_new_method_return (message); - path = ibus_service_get_path((IBusService *)ibus->focused_context); - ibus_message_append_args (reply, - IBUS_TYPE_OBJECT_PATH, &path, - G_TYPE_INVALID); - - return reply; } static void @@ -1364,132 +1273,91 @@ bus_ibus_impl_add_factory (BusIBusImpl *ibus, } -static IBusMessage * -_ibus_register_component (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_register_component (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply; - IBusError *error; - gboolean retval; - GList *engines; - IBusComponent *component; - BusFactoryProxy *factory; - - retval = ibus_message_get_args (message, &error, - IBUS_TYPE_COMPONENT, &component, - G_TYPE_INVALID); + GVariant *variant = g_variant_get_child_value (parameters, 0); + IBusComponent *component = (IBusComponent *)ibus_serializable_deserialize (variant); - if (!retval) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "1st Argument must be IBusComponent: %s", - error->message); - ibus_error_free (error); - return reply; + if (!IBUS_IS_COMPONENT (component)) { + if (component) g_object_unref (component); + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "The first argument should be an IBusComponent."); + return; } g_object_ref_sink (component); - factory = bus_factory_proxy_new (component, connection); + BusConnection *connection = bus_connection_lookup (g_dbus_method_invocation_get_connection (invocation)); + BusFactoryProxy *factory = bus_factory_proxy_new (component, connection); if (factory == NULL) { - reply = ibus_message_new_error (message, - DBUS_ERROR_FAILED, - "Can not create factory"); - return reply; + g_object_unref (component); + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Create factory failed."); + return; } bus_ibus_impl_add_factory (ibus, factory); - engines = ibus_component_get_engines (component); - + GList *engines = ibus_component_get_engines (component); g_list_foreach (engines, (GFunc) g_object_ref, NULL); ibus->register_engine_list = g_list_concat (ibus->register_engine_list, engines); g_object_unref (component); bus_ibus_impl_update_engines_hotkey_profile (ibus); - reply = ibus_message_new_method_return (message); - return reply; + g_dbus_method_invocation_return_value (invocation, NULL); } -static IBusMessage * -_ibus_list_engines (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_list_engines (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply; - IBusMessageIter iter, sub_iter; - GList *engines, *p; - - reply = ibus_message_new_method_return (message); + GVariantBuilder builder; + g_variant_builder_init (&builder, G_VARIANT_TYPE ("av")); - ibus_message_iter_init_append (reply, &iter); - ibus_message_iter_open_container (&iter, IBUS_TYPE_ARRAY, "v", &sub_iter); - - engines = bus_registry_get_engines (ibus->registry); + GList *engines = bus_registry_get_engines (ibus->registry); + GList *p; for (p = engines; p != NULL; p = p->next) { - ibus_message_iter_append (&sub_iter, IBUS_TYPE_ENGINE_DESC, &(p->data)); + g_variant_builder_add (&builder, "v", ibus_serializable_serialize ((IBusSerializable *)p->data)); } g_list_free (engines); - ibus_message_iter_close_container (&iter, &sub_iter); - - return reply; + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(av)", &builder)); } -static IBusMessage * -_ibus_list_active_engines (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_list_active_engines (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply; - IBusMessageIter iter, sub_iter; - GList *p; - - reply = ibus_message_new_method_return (message); - - ibus_message_iter_init_append (reply, &iter); - ibus_message_iter_open_container (&iter, IBUS_TYPE_ARRAY, "v", &sub_iter); + GVariantBuilder builder; + g_variant_builder_init (&builder, G_VARIANT_TYPE ("av")); + GList *p; for (p = ibus->engine_list; p != NULL; p = p->next) { - ibus_message_iter_append (&sub_iter, IBUS_TYPE_ENGINE_DESC, &(p->data)); + g_variant_builder_add (&builder, "v", ibus_serializable_serialize ((IBusSerializable *)p->data)); } - for (p = ibus->register_engine_list; p != NULL; p = p->next) { - ibus_message_iter_append (&sub_iter, IBUS_TYPE_ENGINE_DESC, &(p->data)); + g_variant_builder_add (&builder, "v", ibus_serializable_serialize ((IBusSerializable *)p->data)); } - ibus_message_iter_close_container (&iter, &sub_iter); - - return reply; + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(av)", &builder)); } -static IBusMessage * +static void _ibus_exit (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply; - IBusError *error; - gboolean restart; + gboolean restart = FALSE; + g_variant_get (parameters, "(b)", &restart); - if (!ibus_message_get_args (message, - &error, - G_TYPE_BOOLEAN, &restart, - G_TYPE_INVALID)) { - reply = ibus_message_new_error (message, - DBUS_ERROR_INVALID_ARGS, - "Argument 1 of Exit should be an boolean"); - ibus_error_free (error); - return reply; - } - - reply = ibus_message_new_method_return (message); - ibus_connection_send ((IBusConnection *) connection, reply); - ibus_connection_flush ((IBusConnection *) connection); - ibus_message_unref (reply); + g_dbus_method_invocation_return_value (invocation, NULL); - ibus_object_destroy ((IBusObject *) BUS_DEFAULT_SERVER); + bus_server_quit (); if (!restart) { exit (0); @@ -1526,112 +1394,68 @@ _ibus_exit (BusIBusImpl *ibus, /* should not reach here */ g_assert_not_reached (); - - return NULL; } -static IBusMessage * -_ibus_ping (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_ping (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply; - IBusMessageIter src, dst; - - reply = ibus_message_new_method_return (message); - - ibus_message_iter_init (message, &src); - ibus_message_iter_init_append (reply, &dst); - - ibus_message_iter_copy_data (&dst, &src); - - return reply; + g_dbus_method_invocation_return_value (invocation, parameters); } -static IBusMessage * -_ibus_get_use_sys_layout (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_get_use_sys_layout (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply; - - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - G_TYPE_BOOLEAN, &ibus->use_sys_layout, - G_TYPE_INVALID); - - return reply; + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(b)", ibus->use_sys_layout)); } -static IBusMessage * -_ibus_get_use_global_engine (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_get_use_global_engine (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply; - - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - G_TYPE_BOOLEAN, &ibus->use_global_engine, - G_TYPE_INVALID); - - return reply; + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(b)", ibus->use_global_engine)); } -static IBusMessage * -_ibus_get_global_engine (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_get_global_engine (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply; - if (ibus->use_global_engine && ibus->global_engine) { IBusEngineDesc *desc = bus_engine_proxy_get_desc (ibus->global_engine); if (desc != NULL) { - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - IBUS_TYPE_ENGINE_DESC, &desc, - G_TYPE_INVALID); - return reply; + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)desc); + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(v)", variant)); + return; } } - - reply = ibus_message_new_error (message, DBUS_ERROR_FAILED, - "No global engine."); - return reply; + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "No global engine."); } -static IBusMessage * -_ibus_set_global_engine (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_set_global_engine (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - gboolean retval; - IBusMessage *reply; - IBusError *error; - gchar *new_engine_name; - gchar *old_engine_name; - if (!ibus->use_global_engine) { - reply = ibus_message_new_error (message, DBUS_ERROR_FAILED, - "Global engine feature is disable."); - return reply; - } - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &new_engine_name, - G_TYPE_INVALID); - if (!retval) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply; + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Global engine feature is disabled."); + return; } - reply = ibus_message_new_method_return (message); - old_engine_name = NULL; + const gchar *new_engine_name = NULL; + g_variant_get (parameters, "(&s)", &new_engine_name); + const gchar *old_engine_name = NULL; if (ibus->global_engine) { old_engine_name = bus_engine_proxy_get_desc (ibus->global_engine)->name; @@ -1646,7 +1470,8 @@ _ibus_set_global_engine (BusIBusImpl *ibus, else if (ibus->global_engine) { bus_engine_proxy_enable (ibus->global_engine); } - return reply; + g_dbus_method_invocation_return_value (invocation, NULL); + return; } /* If there is a focused input context, then we just change the engine of @@ -1676,93 +1501,78 @@ _ibus_set_global_engine (BusIBusImpl *ibus, } } } - - return reply; + g_dbus_method_invocation_return_value (invocation, NULL); } -static IBusMessage * -_ibus_is_global_engine_enabled (BusIBusImpl *ibus, - IBusMessage *message, - BusConnection *connection) +static void +_ibus_is_global_engine_enabled (BusIBusImpl *ibus, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - IBusMessage *reply; gboolean enabled = (ibus->use_global_engine && ibus->global_engine && bus_engine_proxy_is_enabled (ibus->global_engine)); - - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - G_TYPE_BOOLEAN, &enabled, - G_TYPE_INVALID); - return reply; + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(b)", enabled)); } - -static gboolean -bus_ibus_impl_ibus_message (BusIBusImpl *ibus, - BusConnection *connection, - IBusMessage *message) -{ - g_assert (BUS_IS_IBUS_IMPL (ibus)); - g_assert (BUS_IS_CONNECTION (connection)); - g_assert (message != NULL); - - gint i; - IBusMessage *reply_message = NULL; +static void +bus_ibus_impl_service_method_call (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + if (g_strcmp0 (interface_name, "org.freedesktop.IBus") != 0) { + IBUS_SERVICE_CLASS(bus_ibus_impl_parent_class)->service_method_call ( + service, connection, sender, object_path, interface_name, method_name, + parameters, invocation); + return; + } static const struct { - const gchar *interface; - const gchar *name; - IBusMessage *(* handler) (BusIBusImpl *, IBusMessage *, BusConnection *); - } handlers[] = { - /* Introspectable interface */ - { DBUS_INTERFACE_INTROSPECTABLE, - "Introspect", _ibus_introspect }, + const gchar *method_name; + void (* method_callback) (BusIBusImpl *, GVariant *, GDBusMethodInvocation *); + } methods [] = { /* IBus interface */ - { IBUS_INTERFACE_IBUS, "GetAddress", _ibus_get_address }, - { IBUS_INTERFACE_IBUS, "CreateInputContext", _ibus_create_input_context }, - { IBUS_INTERFACE_IBUS, "CurrentInputContext", _ibus_current_input_context }, - { IBUS_INTERFACE_IBUS, "RegisterComponent", _ibus_register_component }, - { IBUS_INTERFACE_IBUS, "ListEngines", _ibus_list_engines }, - { IBUS_INTERFACE_IBUS, "ListActiveEngines", _ibus_list_active_engines }, - { IBUS_INTERFACE_IBUS, "Exit", _ibus_exit }, - { IBUS_INTERFACE_IBUS, "Ping", _ibus_ping }, - { IBUS_INTERFACE_IBUS, "GetUseSysLayout", _ibus_get_use_sys_layout }, - { IBUS_INTERFACE_IBUS, "GetUseGlobalEngine", _ibus_get_use_global_engine }, - { IBUS_INTERFACE_IBUS, "GetGlobalEngine", _ibus_get_global_engine }, - { IBUS_INTERFACE_IBUS, "SetGlobalEngine", _ibus_set_global_engine }, - { IBUS_INTERFACE_IBUS, "IsGlobalEngineEnabled", _ibus_is_global_engine_enabled }, + { "GetAddress", _ibus_get_address }, + { "CreateInputContext", _ibus_create_input_context }, + { "CurrentInputContext", _ibus_current_input_context }, + { "RegisterComponent", _ibus_register_component }, + { "ListEngines", _ibus_list_engines }, + { "ListActiveEngines", _ibus_list_active_engines }, + { "Exit", _ibus_exit }, + { "Ping", _ibus_ping }, + { "GetUseSysLayout", _ibus_get_use_sys_layout }, + { "GetUseGlobalEngine", _ibus_get_use_global_engine }, + { "GetGlobalEngine", _ibus_get_global_engine }, + { "SetGlobalEngine", _ibus_set_global_engine }, + { "IsGlobalEngineEnabled", _ibus_is_global_engine_enabled }, }; - ibus_message_set_sender (message, bus_connection_get_unique_name (connection)); - ibus_message_set_destination (message, DBUS_SERVICE_DBUS); - - if (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL) { - for (i = 0; i < G_N_ELEMENTS (handlers); i++) { - if (ibus_message_is_method_call (message, - handlers[i].interface, - handlers[i].name)) { - - reply_message = handlers[i].handler (ibus, message, connection); - if (reply_message) { - - ibus_message_set_sender (reply_message, DBUS_SERVICE_DBUS); - ibus_message_set_destination (reply_message, bus_connection_get_unique_name (connection)); - ibus_message_set_no_reply (reply_message, TRUE); - - ibus_connection_send ((IBusConnection *) connection, reply_message); - ibus_message_unref (reply_message); - } - - g_signal_stop_emission_by_name (ibus, "ibus-message"); - return TRUE; - } + gint i; + for (i = 0; i < G_N_ELEMENTS (methods); i++) { + if (g_strcmp0 (methods[i].method_name, method_name) == 0) { + methods[i].method_callback ((BusIBusImpl *)service, parameters, invocation); + return; } } + g_return_if_reached (); +} + +BusIBusImpl * +bus_ibus_impl_get_default (void) +{ + static BusIBusImpl *ibus = NULL; - return IBUS_SERVICE_CLASS(bus_ibus_impl_parent_class)->ibus_message ( - (IBusService *) ibus, - (IBusConnection *) connection, - message); + if (ibus == NULL) { + ibus = (BusIBusImpl *) g_object_new (BUS_TYPE_IBUS_IMPL, + "object-path", IBUS_PATH_IBUS, + NULL); + } + return ibus; } BusFactoryProxy * @@ -1805,42 +1615,31 @@ bus_ibus_impl_get_registry (BusIBusImpl *ibus) } static void -bus_ibus_impl_registry_changed (BusIBusImpl *ibus) +bus_ibus_impl_emit_signal (BusIBusImpl *ibus, + const gchar *signal_name, + GVariant *parameters) { - g_assert (BUS_IS_IBUS_IMPL (ibus)); - - IBusMessage *message; - - message = ibus_message_new_signal (IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "RegistryChanged"); - ibus_message_append_args (message, - G_TYPE_INVALID); - ibus_message_set_sender (message, IBUS_SERVICE_IBUS); + GDBusMessage *message = g_dbus_message_new_signal ("/org/freedesktop/IBus", + "org.freedesktop.DBus", + signal_name); + g_dbus_message_set_sender (message, "org.freedesktop.DBus"); + if (parameters) + g_dbus_message_set_body (message, parameters); bus_dbus_impl_dispatch_message_by_rule (BUS_DEFAULT_DBUS, message, NULL); + g_object_unref (message); +} - ibus_message_unref (message); - +static void +bus_ibus_impl_registry_changed (BusIBusImpl *ibus) +{ + bus_ibus_impl_emit_signal (ibus, "RegistryChanged", NULL); } static void bus_ibus_impl_global_engine_changed (BusIBusImpl *ibus) { - g_assert (BUS_IS_IBUS_IMPL (ibus)); - - IBusMessage *message; - - message = ibus_message_new_signal (IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "GlobalEngineChanged"); - ibus_message_append_args (message, - G_TYPE_INVALID); - ibus_message_set_sender (message, IBUS_SERVICE_IBUS); - - bus_dbus_impl_dispatch_message_by_rule (BUS_DEFAULT_DBUS, message, NULL); - - ibus_message_unref (message); + bus_ibus_impl_emit_signal (ibus, "GlobalEngineChanged", NULL); } gboolean @@ -1951,19 +1750,16 @@ bus_ibus_impl_filter_keyboard_shortcuts (BusIBusImpl *ibus, static gchar* bus_ibus_impl_load_global_engine_name_from_config (BusIBusImpl *ibus) { - GValue value = { 0 }; - gchar *global_engine_name = NULL; - g_assert (BUS_IS_IBUS_IMPL (ibus)); g_return_val_if_fail (IBUS_IS_CONFIG (ibus->config), NULL); - if (ibus_config_get_value (ibus->config, "general", "global_engine", &value) && - G_VALUE_TYPE (&value) == G_TYPE_STRING) { - global_engine_name = g_value_dup_string (&value); - g_value_unset (&value); + GVariant *variant = ibus_config_get_value (ibus->config, "general", "global_engine"); + gchar *engine_name = NULL; + if (variant != NULL) { + g_variant_get (variant, "s", &engine_name); + g_variant_unref (variant); } - - return global_engine_name; + return engine_name; } static void @@ -1973,31 +1769,25 @@ bus_ibus_impl_save_global_engine_name_to_config (BusIBusImpl *ibus) g_return_if_fail (IBUS_IS_CONFIG (ibus->config)); if (ibus->use_global_engine && ibus->global_engine) { - GValue value = { 0 }; - g_value_init (&value, G_TYPE_STRING); - g_value_set_static_string (&value, bus_engine_proxy_get_desc (ibus->global_engine)->name); - - ibus_config_set_value (ibus->config, "general", "global_engine", &value); - g_value_unset (&value); + ibus_config_set_value (ibus->config, + "general", "global_engine", + g_variant_new ("s", bus_engine_proxy_get_desc (ibus->global_engine)->name)); } } static gchar* bus_ibus_impl_load_global_previous_engine_name_from_config (BusIBusImpl *ibus) { - GValue value = { 0 }; - gchar *global_previous_engine_name = NULL; - g_assert (BUS_IS_IBUS_IMPL (ibus)); g_return_val_if_fail (IBUS_IS_CONFIG (ibus->config), NULL); - if (ibus_config_get_value (ibus->config, "general", "global_previous_engine", &value) && - G_VALUE_TYPE (&value) == G_TYPE_STRING) { - global_previous_engine_name = g_value_dup_string (&value); - g_value_unset (&value); - } - - return global_previous_engine_name; + GVariant *value = ibus_config_get_value (ibus->config, "general", "global_previous_engine"); + if (value == NULL) + return NULL; + gchar *engine_name = NULL; + g_variant_get (value, "(s)", &engine_name); + g_variant_unref (value); + return engine_name; } static void @@ -2007,12 +1797,9 @@ bus_ibus_impl_save_global_previous_engine_name_to_config (BusIBusImpl *ibus) g_return_if_fail (IBUS_IS_CONFIG (ibus->config)); if (ibus->use_global_engine && ibus->global_previous_engine_name) { - GValue value = { 0 }; - g_value_init (&value, G_TYPE_STRING); - g_value_set_static_string (&value, ibus->global_previous_engine_name); - - ibus_config_set_value (ibus->config, "general", "global_previous_engine", &value); - g_value_unset (&value); + ibus_config_set_value (ibus->config, + "general", "global_previous_engine", + g_variant_new ("s", ibus->global_previous_engine_name)); } } @@ -2086,3 +1873,19 @@ bus_ibus_impl_update_engines_hotkey_profile (BusIBusImpl *ibus) g_list_foreach (ibus->register_engine_list, (GFunc) _add_engine_hotkey, ibus); g_list_foreach (ibus->engine_list, (GFunc) _add_engine_hotkey, ibus); } + +gboolean +bus_ibus_impl_is_use_sys_layout (BusIBusImpl *ibus) +{ + g_assert (BUS_IS_IBUS_IMPL(ibus)); + + return ibus->use_sys_layout; +} + +BusInputContext * +bus_ibus_impl_get_focused_input_context (BusIBusImpl *ibus) +{ + g_assert (BUS_IS_IBUS_IMPL(ibus)); + + return ibus->focused_context; +} diff --git a/bus/ibusimpl.h b/bus/ibusimpl.h index 086626a..8c2747b 100644 --- a/bus/ibusimpl.h +++ b/bus/ibusimpl.h @@ -19,8 +19,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __IBUS_IMPL_H_ -#define __IBUS_IMPL_H_ +#ifndef __BUS_IBUS_IMPL_H_ +#define __BUS_IBUS_IMPL_H_ #include #include "connection.h" @@ -62,44 +62,6 @@ G_BEGIN_DECLS typedef struct _BusIBusImpl BusIBusImpl; typedef struct _BusIBusImplClass BusIBusImplClass; -struct _BusIBusImpl { - IBusService parent; - /* instance members */ - - GHashTable *factory_dict; - GList *factory_list; - GList *contexts; - - GList *engine_list; - GList *register_engine_list; - GList *component_list; - - gboolean use_sys_layout; - gboolean embed_preedit_text; - gboolean enable_by_default; - - BusRegistry *registry; - - BusInputContext *focused_context; - BusPanelProxy *panel; - IBusConfig *config; - IBusHotkeyProfile *hotkey_profile; - IBusKeymap *keymap; - - gboolean use_global_engine; - BusEngineProxy *global_engine; - gchar *global_previous_engine_name; - - IBusHotkeyProfile *engines_hotkey_profile; - GHashTable *hotkey_to_engines_map; -}; - -struct _BusIBusImplClass { - IBusServiceClass parent; - - /* class members */ -}; - GType bus_ibus_impl_get_type (void); BusIBusImpl *bus_ibus_impl_get_default (void); BusFactoryProxy *bus_ibus_impl_get_default_factory (BusIBusImpl *ibus); @@ -113,7 +75,6 @@ IBusHotkeyProfile *bus_ibus_impl_get_hotkey_profile (BusIBusImpl *ibus); IBusKeymap *bus_ibus_impl_get_keymap (BusIBusImpl *ibus); BusRegistry *bus_ibus_impl_get_registry (BusIBusImpl *ibus); - gboolean bus_ibus_impl_filter_keyboard_shortcuts (BusIBusImpl *ibus, BusInputContext *context, @@ -121,6 +82,8 @@ gboolean bus_ibus_impl_filter_keyboard_shortcuts guint modifiers, guint prev_keyval, guint prev_modifiers); - +gboolean bus_ibus_impl_is_use_sys_layout (BusIBusImpl *ibus); +BusInputContext *bus_ibus_impl_get_focused_input_context + (BusIBusImpl *ibus); G_END_DECLS #endif diff --git a/bus/inputcontext.c b/bus/inputcontext.c index b5ab201..53143f0 100644 --- a/bus/inputcontext.c +++ b/bus/inputcontext.c @@ -19,14 +19,64 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include -#include -#include -#include "ibusimpl.h" #include "inputcontext.h" +#include "types.h" +#include "marshalers.h" +#include "ibusimpl.h" #include "engineproxy.h" #include "factoryproxy.h" +struct _BusInputContext { + IBusService parent; + + /* instance members */ + BusConnection *connection; + BusEngineProxy *engine; + gchar *client; + + gboolean has_focus; + gboolean enabled; + + /* capabilities */ + guint capabilities; + + /* cursor location */ + gint x; + gint y; + gint w; + gint h; + + /* prev key event */ + guint prev_keyval; + guint prev_modifiers; + + /* preedit text */ + IBusText *preedit_text; + guint preedit_cursor_pos; + gboolean preedit_visible; + guint preedit_mode; + + /* auxiliary text */ + IBusText *auxiliary_text; + gboolean auxiliary_visible; + + /* lookup table */ + IBusLookupTable *lookup_table; + gboolean lookup_table_visible; + + /* filter release */ + gboolean filter_release; + + /* is fake context */ + gboolean fake; +}; + +struct _BusInputContextClass { + IBusServiceClass parent; + + /* class members */ +}; + enum { PROCESS_KEY_EVENT, SET_CURSOR_LOCATION, @@ -64,18 +114,39 @@ static guint context_signals[LAST_SIGNAL] = { 0 }; /* functions prototype */ static void bus_input_context_destroy (BusInputContext *context); -static gboolean bus_input_context_ibus_message (BusInputContext *context, - BusConnection *connection, - IBusMessage *message); +static void bus_input_context_service_method_call + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation); +/* +static GVariant *bus_input_context_service_get_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error); +static gboolean bus_input_context_service_set_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error); +*/ static gboolean bus_input_context_filter_keyboard_shortcuts (BusInputContext *context, guint keyval, guint keycode, guint modifiers); -static gboolean bus_input_context_send_signal (BusInputContext *context, - const gchar *signal_name, - GType first_arg_type, - ...); static void bus_input_context_unset_engine (BusInputContext *context); static void bus_input_context_commit_text (BusInputContext *context, @@ -127,13 +198,97 @@ static guint id = 0; static IBusText *text_empty = NULL; static IBusLookupTable *lookup_table_empty = NULL; static IBusPropList *props_empty = NULL; +static const gchar introspection_xml[] = + "" + " " + /* methods */ + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + /* signals */ + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; G_DEFINE_TYPE (BusInputContext, bus_input_context, IBUS_TYPE_SERVICE) /* when send preedit to client */ +/* FIXME */ +#if 1 +#define PREEDIT_CONDITION (context->capabilities & IBUS_CAP_PREEDIT_TEXT) +#else #define PREEDIT_CONDITION \ ((context->capabilities & IBUS_CAP_PREEDIT_TEXT) && \ (BUS_DEFAULT_IBUS->embed_preedit_text || (context->capabilities & IBUS_CAP_FOCUS) == 0)) +#endif static void _connection_destroy_cb (BusConnection *connection, @@ -145,74 +300,37 @@ _connection_destroy_cb (BusConnection *connection, ibus_object_destroy (IBUS_OBJECT (context)); } - -BusInputContext * -bus_input_context_new (BusConnection *connection, - const gchar *client) -{ - g_assert (BUS_IS_CONNECTION (connection)); - g_assert (client != NULL); - - BusInputContext *context; - gchar *path; - - path = g_strdup_printf (IBUS_PATH_INPUT_CONTEXT, ++id); - - context = (BusInputContext *) g_object_new (BUS_TYPE_INPUT_CONTEXT, - "path", path, - NULL); - g_free (path); - -#if 0 - ibus_service_add_to_connection (IBUS_SERVICE (context), - IBUS_CONNECTION (connection)); -#endif - - g_object_ref_sink (connection); - context->connection = connection; - context->client = g_strdup (client); - - /* it is a fake input context, just need process hotkey */ - context->fake = (g_strcmp0 (client, "fake") == 0); - - g_signal_connect (context->connection, - "destroy", - (GCallback) _connection_destroy_cb, - context); - - return context; -} - static void -bus_input_context_class_init (BusInputContextClass *klass) +bus_input_context_class_init (BusInputContextClass *class) { - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); + IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (class); ibus_object_class->destroy = (IBusObjectDestroyFunc) bus_input_context_destroy; - IBUS_SERVICE_CLASS (klass)->ibus_message = - (ServiceIBusMessageFunc) bus_input_context_ibus_message; + IBUS_SERVICE_CLASS (class)->service_method_call = bus_input_context_service_method_call; + ibus_service_class_add_interfaces (IBUS_SERVICE_CLASS (class), introspection_xml); /* install signals */ context_signals[PROCESS_KEY_EVENT] = g_signal_new (I_("process-key-event"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_BOOL__UINT_UINT, + bus_marshal_BOOL__UINT_UINT_UINT, G_TYPE_BOOLEAN, - 2, + 3, + G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT); context_signals[SET_CURSOR_LOCATION] = g_signal_new (I_("set-cursor-location"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__INT_INT_INT_INT, + bus_marshal_VOID__INT_INT_INT_INT, G_TYPE_NONE, 4, G_TYPE_INT, @@ -222,29 +340,29 @@ bus_input_context_class_init (BusInputContextClass *klass) context_signals[FOCUS_IN] = g_signal_new (I_("focus-in"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[FOCUS_OUT] = g_signal_new (I_("focus-out"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[UPDATE_PREEDIT_TEXT] = g_signal_new (I_("update-preedit-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT_UINT_BOOLEAN, + bus_marshal_VOID__OBJECT_UINT_BOOLEAN, G_TYPE_NONE, 3, IBUS_TYPE_TEXT, @@ -253,31 +371,31 @@ bus_input_context_class_init (BusInputContextClass *klass) context_signals[SHOW_PREEDIT_TEXT] = g_signal_new (I_("show-preedit-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[HIDE_PREEDIT_TEXT] = g_signal_new (I_("hide-preedit-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[UPDATE_AUXILIARY_TEXT] = g_signal_new (I_("update-auxiliary-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT_BOOLEAN, + bus_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, IBUS_TYPE_TEXT, @@ -285,31 +403,31 @@ bus_input_context_class_init (BusInputContextClass *klass) context_signals[SHOW_AUXILIARY_TEXT] = g_signal_new (I_("show-auxiliary-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[HIDE_AUXILIARY_TEXT] = g_signal_new (I_("hide-auxiliary-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[UPDATE_LOOKUP_TABLE] = g_signal_new (I_("update-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT_BOOLEAN, + bus_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, IBUS_TYPE_LOOKUP_TABLE, @@ -317,117 +435,117 @@ bus_input_context_class_init (BusInputContextClass *klass) context_signals[SHOW_LOOKUP_TABLE] = g_signal_new (I_("show-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[HIDE_LOOKUP_TABLE] = g_signal_new (I_("hide-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[PAGE_UP_LOOKUP_TABLE] = g_signal_new (I_("page-up-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[PAGE_DOWN_LOOKUP_TABLE] = g_signal_new (I_("page-down-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[CURSOR_UP_LOOKUP_TABLE] = g_signal_new (I_("cursor-up-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[CURSOR_DOWN_LOOKUP_TABLE] = g_signal_new (I_("cursor-down-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[REGISTER_PROPERTIES] = g_signal_new (I_("register-properties"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT, + bus_marshal_VOID__OBJECT, G_TYPE_NONE, 1, IBUS_TYPE_PROP_LIST); context_signals[UPDATE_PROPERTY] = g_signal_new (I_("update-property"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT, + bus_marshal_VOID__OBJECT, G_TYPE_NONE, 1, IBUS_TYPE_PROPERTY); context_signals[ENABLED] = g_signal_new (I_("enabled"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[DISABLED] = g_signal_new (I_("disabled"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[ENGINE_CHANGED] = g_signal_new (I_("engine-changed"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); context_signals[REQUEST_ENGINE] = g_signal_new (I_("request-engine"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__STRING, + bus_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); @@ -518,180 +636,62 @@ bus_input_context_destroy (BusInputContext *context) IBUS_OBJECT_CLASS(bus_input_context_parent_class)->destroy (IBUS_OBJECT (context)); } -/* introspectable interface */ -static IBusMessage * -_ibus_introspect (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static gboolean +bus_input_context_emit_signal (BusInputContext *context, + const gchar *signal_name, + GVariant *parameters, + GError **error) { - static const gchar *introspect = - DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - - /* methods */ - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - - /* signals */ - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - - " \n" - "\n"; - - IBusMessage *reply_message; - reply_message = ibus_message_new_method_return (message); - ibus_message_append_args (reply_message, - G_TYPE_STRING, &introspect, - G_TYPE_INVALID); - - return reply_message; + GDBusMessage *message = g_dbus_message_new_signal (ibus_service_get_object_path ((IBusService *)context), + "org.freedesktop.IBus.InputContext", + signal_name); + g_dbus_message_set_sender (message, "org.freedesktop.DBus"); + g_dbus_message_set_destination (message, bus_connection_get_unique_name (context->connection)); + if (parameters != NULL) + g_dbus_message_set_body (message, parameters); + + gboolean retval = g_dbus_connection_send_message (bus_connection_get_dbus_connection (context->connection), + message, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, + NULL, error); + g_object_unref (message); + return retval; } -typedef struct { - BusInputContext *context; - IBusMessage *message; -} CallData; - static void -_ic_process_key_event_reply_cb (gpointer data, - gpointer user_data) +_ic_process_key_event_reply_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) { - gboolean retval; - CallData *call_data; - - retval = (gboolean) GPOINTER_TO_INT (data); - call_data = (CallData *) user_data; - - /* make sure the connection is alive */ - if (G_LIKELY (call_data->context->connection != NULL)) { - IBusMessage *reply; - reply = ibus_message_new_method_return (call_data->message); - ibus_message_append_args (reply, - G_TYPE_BOOLEAN, &retval, - G_TYPE_INVALID); - - ibus_connection_send ((IBusConnection *)call_data->context->connection, reply); - ibus_message_unref (reply); + GError *error = NULL; + GVariant *retval = g_dbus_proxy_call_finish ((GDBusProxy *)source, + result, &error); + if (retval != NULL) { + /* XXX: need check retval is floating? */ + g_dbus_method_invocation_return_value ((GDBusMethodInvocation *)user_data, retval); + g_variant_unref (retval); + } + else { + g_dbus_method_invocation_return_gerror ((GDBusMethodInvocation *)user_data, error); + g_error_free (error); } - - g_object_unref (call_data->context); - ibus_message_unref (call_data->message); - g_slice_free (CallData, call_data); } -static IBusMessage * -_ic_process_key_event (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static void +_ic_process_key_event (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - guint keyval, keycode, modifiers; - gboolean retval; - IBusError *error; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_UINT, &keyval, - G_TYPE_UINT, &keycode, - G_TYPE_UINT, &modifiers, - G_TYPE_INVALID); - - if (!retval) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply; - } + guint keyval = IBUS_VoidSymbol; + guint keycode = 0; + guint modifiers = 0; + g_variant_get (parameters, "(uuu)", &keyval, &keycode, &modifiers); if (G_UNLIKELY (!context->has_focus)) { /* workaround: set focus if context does not have focus */ - if (BUS_DEFAULT_IBUS->focused_context == NULL || - BUS_DEFAULT_IBUS->focused_context->fake == TRUE || + BusInputContext *focused_context = bus_ibus_impl_get_focused_input_context (BUS_DEFAULT_IBUS); + if (context == NULL || + focused_context->fake == TRUE || context->fake == FALSE) { /* grab focus, if context is a real IC or current focused IC is fake */ bus_input_context_focus_in (context); @@ -699,192 +699,102 @@ _ic_process_key_event (BusInputContext *context, } if (G_LIKELY (context->has_focus)) { - retval = bus_input_context_filter_keyboard_shortcuts (context, keyval, keycode, modifiers); + gboolean retval = bus_input_context_filter_keyboard_shortcuts (context, keyval, keycode, modifiers); /* If it is keyboard shortcut, reply TRUE to client */ if (G_UNLIKELY (retval)) { - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - G_TYPE_BOOLEAN, &retval, - G_TYPE_INVALID); - return reply; + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE)); + return; } } /* ignore key events, if it is a fake input context */ if (context->has_focus && context->enabled && context->engine && context->fake == FALSE) { - CallData *call_data; - - call_data = g_slice_new (CallData); - - g_object_ref (context); - ibus_message_ref (message); - - call_data->context = context; - call_data->message = message; - bus_engine_proxy_process_key_event (context->engine, keyval, keycode, modifiers, - (GFunc) _ic_process_key_event_reply_cb, - call_data); - return NULL; + _ic_process_key_event_reply_cb, + invocation); } else { - retval = FALSE; - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - G_TYPE_BOOLEAN, &retval, - G_TYPE_INVALID); - return reply; + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE)); } } -static IBusMessage * -_ic_set_cursor_location (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static void +_ic_set_cursor_location (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); + g_dbus_method_invocation_return_value (invocation, NULL); - IBusMessage *reply; - guint x, y, w, h; - gboolean retval; - IBusError *error; - - retval = ibus_message_get_args (message, &error, - G_TYPE_INT, &x, - G_TYPE_INT, &y, - G_TYPE_INT, &w, - G_TYPE_INT, &h, - G_TYPE_INVALID); - - if (!retval) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply; - } - - context->x = x; - context->y = y; - context->h = h; - context->w = w; + g_variant_get (parameters, "(iiii)", + &context->x, &context->y, &context->w, &context->h); if (context->has_focus && context->enabled && context->engine) { - bus_engine_proxy_set_cursor_location (context->engine, x, y, w, h); + bus_engine_proxy_set_cursor_location (context->engine, + context->x, context->y, context->w, context->h); } if (context->capabilities & IBUS_CAP_FOCUS) { g_signal_emit (context, context_signals[SET_CURSOR_LOCATION], 0, - x, - y, - w, - h); + context->x, + context->y, + context->w, + context->h); } - - reply = ibus_message_new_method_return (message); - return reply; } -static IBusMessage * -_ic_focus_in (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static void +_ic_focus_in (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - if (context->capabilities & IBUS_CAP_FOCUS) { bus_input_context_focus_in (context); - reply = ibus_message_new_method_return (message); + g_dbus_method_invocation_return_value (invocation, NULL); } else { - reply = ibus_message_new_error (message, - DBUS_ERROR_FAILED, - "The input context does not support focus."); + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "The input context does not support focus."); } - - return reply; } -static IBusMessage * -_ic_focus_out (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static void +_ic_focus_out (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - if (context->capabilities & IBUS_CAP_FOCUS) { bus_input_context_focus_out (context); - reply = ibus_message_new_method_return (message); + g_dbus_method_invocation_return_value (invocation, NULL); } else { - reply = ibus_message_new_error (message, - DBUS_ERROR_FAILED, - "The input context does not support focus."); + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "The input context does not support focus."); } - - return reply; } -static IBusMessage * -_ic_reset (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static void +_ic_reset (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - if (context->enabled && context->engine) { bus_engine_proxy_reset (context->engine); } - - reply = ibus_message_new_method_return (message); - return reply; + g_dbus_method_invocation_return_value (invocation, NULL); } -static IBusMessage * -_ic_set_capabilities (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static void +_ic_set_capabilities (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - guint caps; - gboolean retval; - IBusError *error; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_UINT, &caps, - G_TYPE_INVALID); - - if (!retval) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply; - } + guint caps = 0; + g_variant_get (parameters, "(u)", &caps); if (context->capabilities != caps) { context->capabilities = caps; @@ -899,43 +809,23 @@ _ic_set_capabilities (BusInputContext *context, bus_engine_proxy_set_capabilities (context->engine, caps); } } - - reply = ibus_message_new_method_return (message); - return reply; + g_dbus_method_invocation_return_value (invocation, NULL); } -static IBusMessage * -_ic_property_activate (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) -{ - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - gchar *prop_name; - gint prop_state; - gboolean retval; - IBusError *error; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &prop_name, - G_TYPE_INT, &prop_state, - G_TYPE_INVALID); - if (!retval) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply; - } +static void +_ic_property_activate (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + gchar *prop_name = NULL; + gint prop_state = 0; + g_variant_get (parameters, "(&su)", &prop_name, &prop_state); if (context->enabled && context->engine) { bus_engine_proxy_property_activate (context->engine, prop_name, prop_state); } + #ifdef OS_CHROMEOS /* Global engine is always enabled in chromeos, * so pass PropertyActivate signal to the focused context. @@ -949,221 +839,122 @@ _ic_property_activate (BusInputContext *context, } #endif - reply = ibus_message_new_method_return (message); - return reply; + g_dbus_method_invocation_return_value (invocation, NULL); } -static IBusMessage * -_ic_enable (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) -{ - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; +static void +_ic_enable (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) +{ bus_input_context_enable (context); - - reply = ibus_message_new_method_return (message); - return reply; + g_dbus_method_invocation_return_value (invocation, NULL); } -static IBusMessage * -_ic_disable (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static void +_ic_disable (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - bus_input_context_disable (context); - - reply = ibus_message_new_method_return (message); - return reply; + g_dbus_method_invocation_return_value (invocation, NULL); } -static IBusMessage * -_ic_is_enabled (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static void +_ic_is_enabled (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - G_TYPE_BOOLEAN, &context->enabled, - G_TYPE_INVALID); - - return reply; + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", context->enabled)); } -static IBusMessage * -_ic_set_engine (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static void +_ic_set_engine (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - gboolean retval; - IBusMessage *reply; - IBusError *error; - gchar *engine_name; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &engine_name, - G_TYPE_INVALID); - if (!retval) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - return reply; - } + gchar *engine_name = NULL; + g_variant_get (parameters, "(&s)", &engine_name); g_signal_emit (context, context_signals[REQUEST_ENGINE], 0, engine_name); if (context->engine == NULL) { - reply = ibus_message_new_error_printf (message, - "org.freedesktop.IBus.NoEngine", - "can not find engine with name %s", - engine_name); - return reply; + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Can not find engine '%s'.", engine_name); + } + else { + bus_input_context_enable (context); + g_dbus_method_invocation_return_value (invocation, NULL); } - - bus_input_context_enable (context); - - reply = ibus_message_new_method_return (message); - return reply; } -static IBusMessage * -_ic_get_engine (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) +static void +_ic_get_engine (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - IBusEngineDesc *desc; - if (context->engine) { - desc = bus_engine_proxy_get_desc (context->engine); - if (desc != NULL) { - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - IBUS_TYPE_ENGINE_DESC, &desc, - G_TYPE_INVALID); - return reply; - } + IBusEngineDesc *desc = bus_engine_proxy_get_desc (context->engine); + g_dbus_method_invocation_return_value (invocation, + 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 have engine."); } - - reply = ibus_message_new_error (message, - DBUS_ERROR_FAILED, - "InputContext does not have factory."); - return reply; -} - -static IBusMessage * -_ic_destroy (BusInputContext *context, - IBusMessage *message, - BusConnection *connection) -{ - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (message != NULL); - g_assert (BUS_IS_CONNECTION (connection)); - - IBusMessage *reply; - reply = ibus_message_new_method_return (message); - - ibus_connection_send ((IBusConnection *) connection, reply); - ibus_connection_flush ((IBusConnection *) connection); - ibus_message_unref (reply); - - ibus_object_destroy ((IBusObject *) context); - - return NULL; } -static gboolean -bus_input_context_ibus_message (BusInputContext *context, - BusConnection *connection, - IBusMessage *message) +static void +bus_input_context_service_method_call (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (BUS_IS_CONNECTION (connection)); - g_assert (message != NULL); - - gint i; - IBusMessage *reply_message = NULL; + if (g_strcmp0 (interface_name, "org.freedesktop.IBus.InputContext") != 0) { + IBUS_SERVICE_CLASS (bus_input_context_parent_class)->service_method_call ( + service, + connection, + sender, + object_path, + interface_name, + method_name, + parameters, + invocation); + return; + } static const struct { - const gchar *interface; - const gchar *name; - IBusMessage *(* handler) (BusInputContext *, IBusMessage *, BusConnection *); - } handlers[] = { - /* Introspectable interface */ - { DBUS_INTERFACE_INTROSPECTABLE, - "Introspect", _ibus_introspect }, - /* IBus interface */ - { IBUS_INTERFACE_INPUT_CONTEXT, "ProcessKeyEvent", _ic_process_key_event }, - { IBUS_INTERFACE_INPUT_CONTEXT, "SetCursorLocation", _ic_set_cursor_location }, - { IBUS_INTERFACE_INPUT_CONTEXT, "FocusIn", _ic_focus_in }, - { IBUS_INTERFACE_INPUT_CONTEXT, "FocusOut", _ic_focus_out }, - { IBUS_INTERFACE_INPUT_CONTEXT, "Reset", _ic_reset }, - { IBUS_INTERFACE_INPUT_CONTEXT, "SetCapabilities", _ic_set_capabilities }, - { IBUS_INTERFACE_INPUT_CONTEXT, "PropertyActivate", _ic_property_activate }, - { IBUS_INTERFACE_INPUT_CONTEXT, "Enable", _ic_enable }, - { IBUS_INTERFACE_INPUT_CONTEXT, "Disable", _ic_disable }, - { IBUS_INTERFACE_INPUT_CONTEXT, "IsEnabled", _ic_is_enabled }, - { IBUS_INTERFACE_INPUT_CONTEXT, "SetEngine", _ic_set_engine }, - { IBUS_INTERFACE_INPUT_CONTEXT, "GetEngine", _ic_get_engine }, - { IBUS_INTERFACE_INPUT_CONTEXT, "Destroy", _ic_destroy }, + const gchar *method_name; + void (* method_callback) (BusInputContext *, GVariant *, GDBusMethodInvocation *); + } methods [] = { + { "ProcessKeyEvent", _ic_process_key_event }, + { "SetCursorLocation", _ic_set_cursor_location }, + { "FocusIn", _ic_focus_in }, + { "FocusOut", _ic_focus_out }, + { "Reset", _ic_reset }, + { "SetCapabilities", _ic_set_capabilities }, + { "PropertyActivate", _ic_property_activate }, + { "Enable", _ic_enable }, + { "Disable", _ic_disable }, + { "IsEnabled", _ic_is_enabled }, + { "SetEngine", _ic_set_engine }, + { "GetEngine", _ic_get_engine }, }; - ibus_message_set_sender (message, bus_connection_get_unique_name (connection)); - ibus_message_set_destination (message, DBUS_SERVICE_DBUS); - - for (i = 0; i < G_N_ELEMENTS (handlers); i++) { - if (ibus_message_is_method_call (message, - handlers[i].interface, - handlers[i].name)) { - - reply_message = handlers[i].handler (context, message, connection); - if (reply_message) { - - ibus_message_set_sender (reply_message, - DBUS_SERVICE_DBUS); - ibus_message_set_destination (reply_message, - bus_connection_get_unique_name (connection)); - ibus_message_set_no_reply (reply_message, TRUE); - - ibus_connection_send (IBUS_CONNECTION (connection), reply_message); - ibus_message_unref (reply_message); - } - - g_signal_stop_emission_by_name (context, "ibus-message"); - return TRUE; + gint i; + for (i = 0; i < G_N_ELEMENTS (methods); i++) { + if (g_strcmp0 (method_name, methods[i].method_name) == 0) { + methods[i].method_callback ((BusInputContext *)service, parameters, invocation); + return; } } - return IBUS_SERVICE_CLASS (bus_input_context_parent_class)->ibus_message ( - (IBusService *)context, - (IBusConnection *)connection, - message); + g_return_if_reached (); } @@ -1327,10 +1118,11 @@ bus_input_context_commit_text (BusInputContext *context, if (text == text_empty || text == NULL) return; - bus_input_context_send_signal (context, + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)text); + bus_input_context_emit_signal (context, "CommitText", - IBUS_TYPE_TEXT, &text, - G_TYPE_INVALID); + g_variant_new ("(v)", variant), + NULL); } static void @@ -1352,12 +1144,11 @@ bus_input_context_update_preedit_text (BusInputContext *context, context->preedit_mode = mode; if (PREEDIT_CONDITION) { - bus_input_context_send_signal (context, + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)context->preedit_text); + bus_input_context_emit_signal (context, "UpdatePreeditText", - IBUS_TYPE_TEXT, &(context->preedit_text), - G_TYPE_UINT, &(context->preedit_cursor_pos), - G_TYPE_BOOLEAN, &(context->preedit_visible), - G_TYPE_INVALID); + g_variant_new ("(vub)", variant, context->preedit_cursor_pos, context->preedit_visible), + NULL); } else { g_signal_emit (context, @@ -1381,9 +1172,10 @@ bus_input_context_show_preedit_text (BusInputContext *context) context->preedit_visible = TRUE; if (PREEDIT_CONDITION) { - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "ShowPreeditText", - G_TYPE_INVALID); + NULL, + NULL); } else { g_signal_emit (context, @@ -1404,9 +1196,10 @@ bus_input_context_hide_preedit_text (BusInputContext *context) context->preedit_visible = FALSE; if (PREEDIT_CONDITION) { - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "HidePreeditText", - G_TYPE_INVALID); + NULL, + NULL); } else { g_signal_emit (context, @@ -1430,11 +1223,11 @@ bus_input_context_update_auxiliary_text (BusInputContext *context, context->auxiliary_visible = visible; if (context->capabilities & IBUS_CAP_AUXILIARY_TEXT) { - bus_input_context_send_signal (context, + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)text); + bus_input_context_emit_signal (context, "UpdateAuxiliaryText", - IBUS_TYPE_TEXT, &(context->auxiliary_text), - G_TYPE_BOOLEAN, &(context->auxiliary_visible), - G_TYPE_INVALID); + g_variant_new ("(vb)", variant, visible), + NULL); } else { g_signal_emit (context, @@ -1457,9 +1250,10 @@ bus_input_context_show_auxiliary_text (BusInputContext *context) context->auxiliary_visible = TRUE; if ((context->capabilities & IBUS_CAP_AUXILIARY_TEXT) == IBUS_CAP_AUXILIARY_TEXT) { - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "ShowAuxiliaryText", - G_TYPE_INVALID); + NULL, + NULL); } else { g_signal_emit (context, @@ -1480,9 +1274,10 @@ bus_input_context_hide_auxiliary_text (BusInputContext *context) context->auxiliary_visible = FALSE; if ((context->capabilities & IBUS_CAP_AUXILIARY_TEXT) == IBUS_CAP_AUXILIARY_TEXT) { - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "HideAuxiliaryText", - G_TYPE_INVALID); + NULL, + NULL); } else { g_signal_emit (context, @@ -1506,11 +1301,11 @@ bus_input_context_update_lookup_table (BusInputContext *context, context->lookup_table_visible = visible; if (context->capabilities & IBUS_CAP_LOOKUP_TABLE) { - bus_input_context_send_signal (context, + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)table); + bus_input_context_emit_signal (context, "UpdateLookupTable", - IBUS_TYPE_LOOKUP_TABLE, &(context->lookup_table), - G_TYPE_BOOLEAN, &(context->lookup_table_visible), - G_TYPE_INVALID); + g_variant_new ("(vb)", variant, visible), + NULL); } else { g_signal_emit (context, @@ -1533,9 +1328,10 @@ bus_input_context_show_lookup_table (BusInputContext *context) context->lookup_table_visible = TRUE; if ((context->capabilities & IBUS_CAP_LOOKUP_TABLE) == IBUS_CAP_LOOKUP_TABLE) { - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "ShowLookupTable", - G_TYPE_INVALID); + NULL, + NULL); } else { g_signal_emit (context, @@ -1556,9 +1352,10 @@ bus_input_context_hide_lookup_table (BusInputContext *context) context->lookup_table_visible = FALSE; if ((context->capabilities & IBUS_CAP_LOOKUP_TABLE) == IBUS_CAP_LOOKUP_TABLE) { - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "HideLookupTable", - G_TYPE_INVALID); + NULL, + NULL); } else { g_signal_emit (context, @@ -1577,9 +1374,10 @@ bus_input_context_page_up_lookup_table (BusInputContext *context) } if ((context->capabilities & IBUS_CAP_LOOKUP_TABLE) == IBUS_CAP_LOOKUP_TABLE) { - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "PageUpLookupTable", - G_TYPE_INVALID); + NULL, + NULL); } else { g_signal_emit (context, @@ -1598,9 +1396,10 @@ bus_input_context_page_down_lookup_table (BusInputContext *context) } if ((context->capabilities & IBUS_CAP_LOOKUP_TABLE) == IBUS_CAP_LOOKUP_TABLE) { - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "PageDownLookupTable", - G_TYPE_INVALID); + NULL, + NULL); } else { g_signal_emit (context, @@ -1619,9 +1418,10 @@ bus_input_context_cursor_up_lookup_table (BusInputContext *context) } if ((context->capabilities & IBUS_CAP_LOOKUP_TABLE) == IBUS_CAP_LOOKUP_TABLE) { - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "CursorUpLookupTable", - G_TYPE_INVALID); + NULL, + NULL); } else { g_signal_emit (context, @@ -1640,9 +1440,10 @@ bus_input_context_cursor_down_lookup_table (BusInputContext *context) } if ((context->capabilities & IBUS_CAP_LOOKUP_TABLE) == IBUS_CAP_LOOKUP_TABLE) { - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "CursorDownLookupTable", - G_TYPE_INVALID); + NULL, + NULL); } else { g_signal_emit (context, @@ -1659,10 +1460,11 @@ bus_input_context_register_properties (BusInputContext *context, g_assert (IBUS_IS_PROP_LIST (props)); if (context->capabilities & IBUS_CAP_PROPERTY) { - bus_input_context_send_signal (context, + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)props); + bus_input_context_emit_signal (context, "RegisterProperties", - IBUS_TYPE_PROP_LIST, &props, - G_TYPE_INVALID); + g_variant_new ("(v)", variant), + NULL); } else { g_signal_emit (context, @@ -1680,10 +1482,11 @@ bus_input_context_update_property (BusInputContext *context, g_assert (IBUS_IS_PROPERTY (prop)); if (context->capabilities & IBUS_CAP_PROPERTY) { - bus_input_context_send_signal (context, + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)prop); + bus_input_context_emit_signal (context, "UpdateProperty", - IBUS_TYPE_PROPERTY, &prop, - G_TYPE_INVALID); + g_variant_new ("(v)", variant), + NULL); } else { g_signal_emit (context, @@ -1734,12 +1537,10 @@ _engine_forward_key_event_cb (BusEngineProxy *engine, if (!context->enabled) return; - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "ForwardKeyEvent", - G_TYPE_UINT, &keyval, - G_TYPE_UINT, &keycode, - G_TYPE_UINT, &state, - G_TYPE_INVALID); + g_variant_new ("(uuu)", keyval, keycode, state), + NULL); } static void @@ -1756,11 +1557,10 @@ _engine_delete_surrounding_text_cb (BusEngineProxy *engine, if (!context->enabled) return; - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "DeleteSurroundingText", - G_TYPE_INT, &offset_from_cursor, - G_TYPE_UINT, &nchars, - G_TYPE_INVALID); + g_variant_new ("(iu)", offset_from_cursor, nchars), + NULL); } static void @@ -1881,6 +1681,45 @@ DEFINE_FUNCTION (cursor_up_lookup_table) DEFINE_FUNCTION (cursor_down_lookup_table) #undef DEFINE_FUNCTION +BusInputContext * +bus_input_context_new (BusConnection *connection, + const gchar *client) +{ + g_assert (BUS_IS_CONNECTION (connection)); + g_assert (client != NULL); + + BusInputContext *context; + gchar *path; + + path = g_strdup_printf (IBUS_PATH_INPUT_CONTEXT, ++id); + + context = (BusInputContext *) g_object_new (BUS_TYPE_INPUT_CONTEXT, + "object-path", path, + "connection", bus_connection_get_dbus_connection (connection), + NULL); + g_free (path); + + +#if 0 + ibus_service_add_to_connection (IBUS_SERVICE (context), + IBUS_CONNECTION (connection)); +#endif + + g_object_ref_sink (connection); + context->connection = connection; + context->client = g_strdup (client); + + /* it is a fake input context, just need process hotkey */ + context->fake = (g_strcmp0 (client, "fake") == 0); + + g_signal_connect (context->connection, + "destroy", + (GCallback) _connection_destroy_cb, + context); + + return context; +} + void bus_input_context_enable (BusInputContext *context) { @@ -1906,9 +1745,10 @@ bus_input_context_enable (BusInputContext *context) bus_engine_proxy_set_capabilities (context->engine, context->capabilities); bus_engine_proxy_set_cursor_location (context->engine, context->x, context->y, context->w, context->h); - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "Enabled", - G_TYPE_INVALID); + NULL, + NULL); g_signal_emit (context, context_signals[ENABLED], 0); @@ -1929,9 +1769,10 @@ bus_input_context_disable (BusInputContext *context) bus_engine_proxy_disable (context->engine); } - bus_input_context_send_signal (context, + bus_input_context_emit_signal (context, "Disabled", - G_TYPE_INVALID); + NULL, + NULL); g_signal_emit (context, context_signals[DISABLED], 0); @@ -2062,7 +1903,7 @@ bus_input_context_filter_keyboard_shortcuts (BusInputContext *context, } } - if (keycode != 0 && !BUS_DEFAULT_IBUS->use_sys_layout) { + if (keycode != 0 && bus_ibus_impl_is_use_sys_layout (BUS_DEFAULT_IBUS)) { IBusKeymap *keymap = BUS_DEFAULT_KEYMAP; if (keymap != NULL) { guint tmp = ibus_keymap_lookup_keysym (keymap, @@ -2090,37 +1931,6 @@ bus_input_context_filter_keyboard_shortcuts (BusInputContext *context, return retval; } - -static gboolean -bus_input_context_send_signal (BusInputContext *context, - const gchar *signal_name, - GType first_arg_type, - ...) -{ - g_assert (BUS_IS_INPUT_CONTEXT (context)); - g_assert (signal_name != NULL); - g_assert (context->connection != NULL); - - va_list args; - gboolean retval; - IBusMessage *message; - - message = ibus_message_new_signal (ibus_service_get_path ((IBusService *)context), - IBUS_INTERFACE_INPUT_CONTEXT, - signal_name); - - ibus_message_set_sender (message, IBUS_SERVICE_IBUS); - - va_start (args, first_arg_type); - ibus_message_append_args_valist (message, first_arg_type, args); - va_end (args); - - retval = ibus_connection_send ((IBusConnection *)context->connection, message); - ibus_message_unref (message); - - return retval; -} - guint bus_input_context_get_capabilities (BusInputContext *context) { diff --git a/bus/inputcontext.h b/bus/inputcontext.h index 576672f..b3c3975 100644 --- a/bus/inputcontext.h +++ b/bus/inputcontext.h @@ -19,8 +19,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __INPUT_CONTEXT_H_ -#define __INPUT_CONTEXT_H_ +#ifndef __BUS_INPUT_CONTEXT_H_ +#define __BUS_INPUT_CONTEXT_H_ #include #include "connection.h" @@ -49,57 +49,6 @@ G_BEGIN_DECLS typedef struct _BusInputContext BusInputContext; typedef struct _BusInputContextClass BusInputContextClass; -struct _BusInputContext { - IBusService parent; - - /* instance members */ - BusConnection *connection; - BusEngineProxy *engine; - gchar *client; - - gboolean has_focus; - gboolean enabled; - - /* capabilities */ - guint capabilities; - - /* cursor location */ - gint x; - gint y; - gint w; - gint h; - - /* prev key event */ - guint prev_keyval; - guint prev_modifiers; - - /* preedit text */ - IBusText *preedit_text; - guint preedit_cursor_pos; - gboolean preedit_visible; - guint preedit_mode; - - /* auxiliary text */ - IBusText *auxiliary_text; - gboolean auxiliary_visible; - - /* lookup table */ - IBusLookupTable *lookup_table; - gboolean lookup_table_visible; - - /* filter release */ - gboolean filter_release; - - /* is fake context */ - gboolean fake; -}; - -struct _BusInputContextClass { - IBusServiceClass parent; - - /* class members */ -}; - GType bus_input_context_get_type (void); BusInputContext *bus_input_context_new (BusConnection *connection, const gchar *client); diff --git a/bus/main.c b/bus/main.c index c9821b8..1b2ba64 100644 --- a/bus/main.c +++ b/bus/main.c @@ -20,7 +20,6 @@ * Boston, MA 02111-1307, USA. */ #include -#include #include #include #include @@ -29,6 +28,9 @@ #include #include #include +#include +#include +#include #include "server.h" #include "ibusimpl.h" @@ -42,7 +44,7 @@ static gboolean restart = FALSE; static gchar *panel = "default"; static gchar *config = "default"; static gchar *desktop = "gnome"; -static gchar *address = ""; +gchar *g_address = "unix:tmpdir=/tmp"; gchar *g_cache = "auto"; gboolean g_mempro = FALSE; gboolean g_verbose = FALSE; @@ -67,7 +69,7 @@ static const GOptionEntry entries[] = { "desktop", 'n', 0, G_OPTION_ARG_STRING, &desktop, "specify the name of desktop session. [default=gnome]", "name" }, { "panel", 'p', 0, G_OPTION_ARG_STRING, &panel, "specify the cmdline of panel program.", "cmdline" }, { "config", 'c', 0, G_OPTION_ARG_STRING, &config, "specify the cmdline of config program.", "cmdline" }, - { "address", 'a', 0, G_OPTION_ARG_STRING, &address, "specify the address of ibus daemon.", "address" }, + { "address", 'a', 0, G_OPTION_ARG_STRING, &g_address, "specify the address of ibus daemon.", "address" }, { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "if there is an old ibus-daemon is running, it will be replaced.", NULL }, { "cache", 't', 0, G_OPTION_ARG_STRING, &g_cache, "specify the cache mode. [auto/refresh/none]", NULL }, { "timeout", 'o', 0, G_OPTION_ARG_INT, &g_dbus_timeout, "dbus reply timeout in milliseconds.", "timeout [default is 2000]" }, @@ -85,12 +87,9 @@ execute_cmdline (const gchar *cmdline) { g_assert (cmdline); - gint argc; - gchar **argv; - gboolean retval; - GError *error; - - error = NULL; + gint argc = 0; + gchar **argv = NULL; + GError *error = NULL; if (!g_shell_parse_argv (cmdline, &argc, &argv, &error)) { g_warning ("Can not parse cmdline `%s` exec: %s", cmdline, error->message); g_error_free (error); @@ -98,7 +97,7 @@ execute_cmdline (const gchar *cmdline) } error = NULL; - retval = g_spawn_async (NULL, argv, NULL, + gboolean retval = g_spawn_async (NULL, argv, NULL, G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, &error); @@ -165,21 +164,16 @@ _sig_usr2_handler (int sig) gint main (gint argc, gchar **argv) { - GOptionContext *context; - BusServer *server; - IBusBus *bus; - - GError *error = NULL; - setlocale (LC_ALL, ""); - context = g_option_context_new ("- ibus daemon"); - + GOptionContext *context = g_option_context_new ("- ibus daemon"); g_option_context_add_main_entries (context, entries, "ibus-daemon"); g_argv = g_strdupv (argv); + GError *error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Option parsing failed: %s\n", error->message); + g_error_free (error); exit (-1); } @@ -211,7 +205,7 @@ main (gint argc, gchar **argv) /* create a new process group */ setpgid (0, 0); - g_type_init (); + ibus_init (); #ifdef G_THREADS_ENABLED g_thread_init (NULL); @@ -219,8 +213,9 @@ main (gint argc, gchar **argv) ibus_set_log_handler(g_verbose); /* check if ibus-daemon is running in this session */ +#if 0 if (ibus_get_address () != NULL) { - bus = ibus_bus_new (); + IBusBus *bus = ibus_bus_new (); if (ibus_bus_is_connected (bus)) { if (!replace) { @@ -235,11 +230,9 @@ main (gint argc, gchar **argv) g_object_unref (bus); bus = NULL; } - - /* create ibus server */ - server = bus_server_get_default (); - bus_server_listen (server); - +#endif + bus_server_init (); + /* FIXME */ if (!single) { /* execute config component */ if (g_strcmp0 (config, "default") == 0) { @@ -280,7 +273,6 @@ main (gint argc, gchar **argv) exit (-1); } - bus_server_run (server); - + bus_server_run (); return 0; } diff --git a/bus/marshalers.list b/bus/marshalers.list new file mode 100644 index 0000000..15bdf02 --- /dev/null +++ b/bus/marshalers.list @@ -0,0 +1,13 @@ +VOID:VOID +VOID:STRING +VOID:OBJECT +VOID:INT,UINT +VOID:UINT,UINT,UINT +VOID:INT,INT,INT,INT +VOID:STRING,INT +VOID:OBJECT +VOID:STRING,STRING,STRING +VOID:OBJECT,BOOLEAN +VOID:OBJECT,UINT,BOOLEAN +VOID:OBJECT,UINT,BOOLEAN,UINT +BOOL:UINT,UINT,UINT diff --git a/bus/matchrule.c b/bus/matchrule.c index eb51323..7ea9d6c 100644 --- a/bus/matchrule.c +++ b/bus/matchrule.c @@ -19,17 +19,87 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include -#include #include "matchrule.h" +#include -#define BUS_CONFIG_PROXY_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), BUS_TYPE_CONFIG_PROXY, BusMatchRulePrivate)) +typedef enum { + MATCH_TYPE = 1 << 0, + MATCH_INTERFACE = 1 << 1, + MATCH_MEMBER = 1 << 2, + MATCH_SENDER = 1 << 3, + MATCH_DESTINATION = 1 << 4, + MATCH_PATH = 1 << 5, + MATCH_ARGS = 1 << 6, +} BusMatchFlags; + +struct _BusMatchRule { + IBusObject parent; + /* instance members */ + gint flags; + gint message_type; + gchar *interface; + gchar *member; + gchar *sender; + gchar *destination; + gchar *path; + GArray *args; + GList *recipients; +}; + +struct _BusMatchRuleClass { + IBusObjectClass parent; + /* class members */ +}; + +typedef struct _BusRecipient BusRecipient; +struct _BusRecipient { + BusConnection *connection; + gint refcount; +}; + +static BusRecipient *bus_recipient_new (BusConnection *connection); +static void bus_recipient_free (BusRecipient *recipient); +static BusRecipient *bus_recipient_ref (BusRecipient *recipient); +static gboolean bus_recipient_unref (BusRecipient *recipient); +static void bus_match_rule_destroy (BusMatchRule *rule); +static void bus_match_rule_connection_destroy_cb + (BusConnection *connection, + BusMatchRule *rule); +static BusRecipient * +bus_recipient_new (BusConnection *connection) +{ + BusRecipient *recipient = g_slice_new (BusRecipient); + g_object_ref (connection); + recipient->connection = connection; + recipient->refcount = 1; + return recipient; +} -static void bus_match_rule_destroy (BusMatchRule *rule); -static void _connection_destroy_cb (BusConnection *connection, - BusMatchRule *rule); +static void +bus_recipient_free (BusRecipient *recipient) +{ + g_object_unref (recipient->connection); + g_slice_free (BusRecipient, recipient); +} + +static BusRecipient * +bus_recipient_ref (BusRecipient *recipient) +{ + recipient->refcount ++; + return recipient; +} + +static gboolean +bus_recipient_unref (BusRecipient *recipient) +{ + recipient->refcount --; + if (recipient->refcount == 0) { + bus_recipient_free (recipient); + return TRUE; + } + return FALSE; +} G_DEFINE_TYPE (BusMatchRule, bus_match_rule, IBUS_TYPE_OBJECT) @@ -45,7 +115,7 @@ static void bus_match_rule_init (BusMatchRule *rule) { rule->flags = 0; - rule->message_type = DBUS_MESSAGE_TYPE_INVALID; + rule->message_type = G_DBUS_MESSAGE_TYPE_INVALID; rule->interface = NULL; rule->member = NULL; rule->sender = NULL; @@ -64,19 +134,17 @@ bus_match_rule_destroy (BusMatchRule *rule) g_free (rule->path); gint i; - GList *link; - for (i = 0; i < rule->args->len; i++) { g_free (g_array_index (rule->args, gchar *, i)); } g_array_free (rule->args, TRUE); - for (link = rule->recipients; link != NULL; link = link->next) { - BusRecipient *recipient = (BusRecipient *) link->data; + GList *p; + for (p = rule->recipients; p != NULL; p = p->next) { + BusRecipient *recipient = (BusRecipient *) p->data; g_signal_handlers_disconnect_by_func (recipient->connection, - G_CALLBACK (_connection_destroy_cb), rule); - g_object_unref (recipient->connection); - g_slice_free (BusRecipient, recipient); + G_CALLBACK (bus_match_rule_connection_destroy_cb), rule); + bus_recipient_free (recipient); } g_list_free (rule->recipients); @@ -255,16 +323,16 @@ bus_match_rule_new (const gchar *text) for (p = tokens; p != NULL && p->key != 0; p++) { if (g_strcmp0 (p->key, "type") == 0) { if (g_strcmp0 (p->value, "signal") == 0) { - bus_match_rule_set_message_type (rule, DBUS_MESSAGE_TYPE_SIGNAL); + bus_match_rule_set_message_type (rule, G_DBUS_MESSAGE_TYPE_SIGNAL); } else if (g_strcmp0 (p->value, "method_call") == 0) { - bus_match_rule_set_message_type (rule, DBUS_MESSAGE_TYPE_METHOD_CALL); + bus_match_rule_set_message_type (rule, G_DBUS_MESSAGE_TYPE_METHOD_CALL); } else if (g_strcmp0 (p->value, "method_return") == 0) { - bus_match_rule_set_message_type (rule, DBUS_MESSAGE_TYPE_METHOD_RETURN); + bus_match_rule_set_message_type (rule, G_DBUS_MESSAGE_TYPE_METHOD_RETURN); } else if (g_strcmp0 (p->value, "error") == 0) { - bus_match_rule_set_message_type (rule, DBUS_MESSAGE_TYPE_ERROR); + bus_match_rule_set_message_type (rule, G_DBUS_MESSAGE_TYPE_ERROR); } else goto failed; @@ -308,10 +376,10 @@ bus_match_rule_set_message_type (BusMatchRule *rule, gint type) { g_assert (rule != NULL); - g_assert (type == DBUS_MESSAGE_TYPE_SIGNAL || - type == DBUS_MESSAGE_TYPE_METHOD_CALL || - type == DBUS_MESSAGE_TYPE_METHOD_RETURN || - type == DBUS_MESSAGE_TYPE_ERROR); + g_assert (type == G_DBUS_MESSAGE_TYPE_SIGNAL || + type == G_DBUS_MESSAGE_TYPE_METHOD_CALL || + type == G_DBUS_MESSAGE_TYPE_METHOD_RETURN || + type == G_DBUS_MESSAGE_TYPE_ERROR); rule->flags |= MATCH_TYPE; rule->message_type = type; @@ -414,66 +482,68 @@ bus_match_rule_set_arg (BusMatchRule *rule, gboolean bus_match_rule_match (BusMatchRule *rule, - IBusMessage *message) + GDBusMessage *message) { g_assert (rule != NULL); g_assert (message != NULL); if (rule->flags & MATCH_TYPE) { - if (ibus_message_get_type (message) != rule->message_type) + if (g_dbus_message_get_message_type (message) != rule->message_type) return FALSE; } if (rule->flags & MATCH_INTERFACE) { - if (g_strcmp0 (ibus_message_get_interface (message), rule->interface) != 0) + if (g_strcmp0 (g_dbus_message_get_interface (message), rule->interface) != 0) return FALSE; } if (rule->flags & MATCH_MEMBER) { - if (g_strcmp0 (ibus_message_get_member (message), rule->member) != 0) + if (g_strcmp0 (g_dbus_message_get_member (message), rule->member) != 0) return FALSE; } if (rule->flags & MATCH_SENDER) { - if (g_strcmp0 (ibus_message_get_sender (message), rule->sender) != 0) + if (g_strcmp0 (g_dbus_message_get_sender (message), rule->sender) != 0) return FALSE; } if (rule->flags & MATCH_DESTINATION) { - if (g_strcmp0 (ibus_message_get_destination (message), rule->destination) != 0) + if (g_strcmp0 (g_dbus_message_get_destination (message), rule->destination) != 0) return FALSE; } if (rule->flags & MATCH_PATH) { - if (g_strcmp0 (ibus_message_get_path (message), rule->path) != 0) + if (g_strcmp0 (g_dbus_message_get_path (message), rule->path) != 0) return FALSE; } if (rule->flags & MATCH_ARGS) { guint i; - IBusMessageIter iter; - - ibus_message_iter_init (message, &iter); + GVariant *arguments = g_dbus_message_get_body (message); + if (arguments == NULL) + return FALSE; for (i = 0; i < rule->args->len; i++) { - gchar *arg = g_array_index (rule->args, gchar *, i); - if (arg != NULL) { - gint type; - gchar *value; - - type = ibus_message_iter_get_arg_type (&iter); - if (type != G_TYPE_STRING && type != IBUS_TYPE_OBJECT_PATH) - return FALSE; - - ibus_message_iter_get_basic (&iter, &value); - - if (g_strcmp0 (arg, value) != 0) - return FALSE; + const gchar *arg = g_array_index (rule->args, const gchar *, i); + if (arg == NULL) + continue; + GVariant * variant = g_variant_get_child_value (arguments, i); + if (variant == NULL) + return FALSE; + switch (g_variant_classify (variant)) { + case G_VARIANT_CLASS_STRING: + case G_VARIANT_CLASS_OBJECT_PATH: + if (g_strcmp0 (arg, g_variant_get_string (variant, NULL)) == 0) { + g_variant_unref (variant); + continue; + } + default: + break; } - ibus_message_iter_next (&iter); + g_variant_unref (variant); + return FALSE; } } - return TRUE; } @@ -534,22 +604,16 @@ bus_match_rule_is_equal (BusMatchRule *a, } static void -_connection_destroy_cb (BusConnection *connection, - BusMatchRule *rule) +bus_match_rule_connection_destroy_cb (BusConnection *connection, + BusMatchRule *rule) { - g_assert (BUS_IS_MATCH_RULE (rule)); - g_assert (BUS_IS_CONNECTION (connection)); - - GList *link; - BusRecipient *recipient; - - for (link = rule->recipients; link != NULL; link = link->next) { - recipient = (BusRecipient *)link->data; + GList *p; + for (p = rule->recipients; p != NULL; p = p->next) { + BusRecipient *recipient = (BusRecipient *)p->data; if (recipient->connection == connection) { - rule->recipients = g_list_remove_link (rule->recipients, link); - g_object_unref (connection); - g_slice_free (BusRecipient, recipient); + rule->recipients = g_list_remove_link (rule->recipients, p); + bus_recipient_free (recipient); return; } @@ -561,57 +625,46 @@ _connection_destroy_cb (BusConnection *connection, } void -bus_match_rule_add_recipient (BusMatchRule *rule, - BusConnection *connection) +bus_match_rule_add_recipient (BusMatchRule *rule, + BusConnection *connection) { g_assert (BUS_IS_MATCH_RULE (rule)); g_assert (BUS_IS_CONNECTION (connection)); - GList *link; - BusRecipient *recipient; - - for (link = rule->recipients; link != NULL; link = link->next) { - recipient = (BusRecipient *) link->data; + GList *p; + for (p = rule->recipients; p != NULL; p = p->next) { + BusRecipient *recipient = (BusRecipient *) p->data; if (connection == recipient->connection) { - recipient->refcount ++; + bus_recipient_ref (recipient); return; } } - recipient = g_slice_new (BusRecipient); - - g_object_ref_sink (connection); - recipient->connection = connection; - recipient->refcount = 1; - + /* alloc a new recipient */ + BusRecipient *recipient = bus_recipient_new (connection); rule->recipients = g_list_append (rule->recipients, recipient); g_signal_connect (connection, "destroy", - G_CALLBACK (_connection_destroy_cb), + G_CALLBACK (bus_match_rule_connection_destroy_cb), rule); } void -bus_match_rule_remove_recipient (BusMatchRule *rule, - BusConnection *connection) +bus_match_rule_remove_recipient (BusMatchRule *rule, + BusConnection *connection) { g_assert (BUS_IS_MATCH_RULE (rule)); g_assert (BUS_IS_CONNECTION (connection)); - GList *link; - BusRecipient *recipient; - - for (link = rule->recipients; link != NULL; link = link->next) { - recipient = (BusRecipient *) link->data; + GList *p; + for (p = rule->recipients; p != NULL; p = p->next) { + BusRecipient *recipient = (BusRecipient *) p->data; if (connection == recipient->connection) { - recipient->refcount --; - if (recipient->refcount == 0) { - rule->recipients = g_list_remove_link (rule->recipients, link); - g_slice_free (BusRecipient, recipient); + if (bus_recipient_unref (recipient)) { + rule->recipients = g_list_remove_link (rule->recipients, p); g_signal_handlers_disconnect_by_func (connection, - G_CALLBACK (_connection_destroy_cb), + G_CALLBACK (bus_match_rule_connection_destroy_cb), rule); - g_object_unref (connection); } if (rule->recipients == NULL ) { @@ -620,13 +673,12 @@ bus_match_rule_remove_recipient (BusMatchRule *rule, return; } } - - g_warning ("Remove recipient failed"); + g_return_if_reached (); } GList * bus_match_rule_get_recipients (BusMatchRule *rule, - IBusMessage *message) + GDBusMessage *message) { g_assert (BUS_IS_MATCH_RULE (rule)); g_assert (message != NULL); diff --git a/bus/matchrule.h b/bus/matchrule.h index 4743b81..8310d95 100644 --- a/bus/matchrule.h +++ b/bus/matchrule.h @@ -19,8 +19,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __MATCH_RULE_H_ -#define __MATCH_RULE_H_ +#ifndef __BUS_MATCH_RULE_H_ +#define __BUS_MATCH_RULE_H_ #include #include "connection.h" @@ -48,77 +48,42 @@ G_BEGIN_DECLS typedef struct _BusMatchRule BusMatchRule; typedef struct _BusMatchRuleClass BusMatchRuleClass; -typedef enum { - MATCH_TYPE = 1 << 0, - MATCH_INTERFACE = 1 << 1, - MATCH_MEMBER = 1 << 2, - MATCH_SENDER = 1 << 3, - MATCH_DESTINATION = 1 << 4, - MATCH_PATH = 1 << 5, - MATCH_ARGS = 1 << 6, -} BusMatchFlags; - -typedef struct _BusRecipient BusRecipient; -struct _BusRecipient { - BusConnection *connection; - gint refcount; -}; - -struct _BusMatchRule { - IBusObject parent; - /* instance members */ - gint flags; - gint message_type; - gchar *interface; - gchar *member; - gchar *sender; - gchar *destination; - gchar *path; - GArray *args; - GList *recipients; -}; - -struct _BusMatchRuleClass { - IBusObjectClass parent; - /* class members */ -}; - GType bus_match_rule_get_type (void); -BusMatchRule *bus_match_rule_new (const gchar *text); -BusMatchRule *bus_match_rule_ref (BusMatchRule *rule); -void bus_match_rule_unref (BusMatchRule *rule); -void bus_match_rule_free (BusMatchRule *rule); +BusMatchRule *bus_match_rule_new (const gchar *text); +BusMatchRule *bus_match_rule_ref (BusMatchRule *rule); +void bus_match_rule_unref (BusMatchRule *rule); +void bus_match_rule_free (BusMatchRule *rule); gboolean bus_match_rule_set_message_type - (BusMatchRule *rule, - gint type); -gboolean bus_match_rule_set_sender (BusMatchRule *rule, - const gchar *sender); + (BusMatchRule *rule, + gint type); +gboolean bus_match_rule_set_sender (BusMatchRule *rule, + const gchar *sender); gboolean bus_match_rule_set_interface - (BusMatchRule *rule, - const gchar *interface); -gboolean bus_match_rule_set_member (BusMatchRule *rule, - const gchar *member); -gboolean bus_match_rule_set_path (BusMatchRule *rule, - const gchar *path); + (BusMatchRule *rule, + const gchar *interface); +gboolean bus_match_rule_set_member (BusMatchRule *rule, + const gchar *member); +gboolean bus_match_rule_set_path (BusMatchRule *rule, + const gchar *path); gboolean bus_match_rule_set_destination - (BusMatchRule *rule, - const gchar *dest); -gboolean bus_match_rule_set_arg (BusMatchRule *rule, - guint arg_i, - const gchar *arg); -gboolean bus_match_rule_match (BusMatchRule *rule, - IBusMessage *message); -gboolean bus_match_rule_is_equal (BusMatchRule *a, - BusMatchRule *b); + (BusMatchRule *rule, + const gchar *dest); +gboolean bus_match_rule_set_arg (BusMatchRule *rule, + guint arg_i, + const gchar *arg); +gboolean bus_match_rule_match (BusMatchRule *rule, + GDBusMessage *message); +gboolean bus_match_rule_is_equal (BusMatchRule *a, + BusMatchRule *b); void bus_match_rule_add_recipient - (BusMatchRule *rule, - BusConnection *connection); + (BusMatchRule *rule, + BusConnection *connection); void bus_match_rule_remove_recipient - (BusMatchRule *rule, - BusConnection *connection); + (BusMatchRule *rule, + BusConnection *connection); GList *bus_match_rule_get_recipients (BusMatchRule *rule, - IBusMessage *message); + GDBusMessage *message); G_END_DECLS #endif diff --git a/bus/option.h b/bus/option.h index 25153ed..37dc826 100644 --- a/bus/option.h +++ b/bus/option.h @@ -19,8 +19,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __OPTION_H_ -#define __OPTION_H_ +#ifndef __BUS_OPTION_H_ +#define __BUS_OPTION_H_ G_BEGIN_DECLS @@ -28,6 +28,7 @@ extern gchar *g_cache; extern gboolean g_mempro; extern gboolean g_verbose; extern gint g_dbus_timeout; +extern gchar *g_address; G_END_DECLS #endif diff --git a/bus/panelproxy.c b/bus/panelproxy.c index c8013ab..82b836c 100644 --- a/bus/panelproxy.c +++ b/bus/panelproxy.c @@ -19,10 +19,9 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include -#include -#include #include "panelproxy.h" +#include "types.h" +#include "marshalers.h" enum { PAGE_UP, @@ -36,15 +35,41 @@ enum { LAST_SIGNAL, }; +struct _BusPanelProxy { + IBusProxy parent; + + /* instance members */ + BusInputContext *focused_context; +}; + +struct _BusPanelProxyClass { + IBusProxyClass parent; + /* class members */ + + void (* page_up) (BusPanelProxy *panel); + void (* page_down) (BusPanelProxy *panel); + void (* cursor_up) (BusPanelProxy *panel); + void (* cursor_down) (BusPanelProxy *panel); + void (* candidate_clicked) (BusPanelProxy *panel, + guint index, + guint button, + guint state); + + void (* property_activate) (BusPanelProxy *panel, + const gchar *prop_name, + gint prop_state); +}; + static guint panel_signals[LAST_SIGNAL] = { 0 }; // static guint engine_signals[LAST_SIGNAL] = { 0 }; /* functions prototype */ static void bus_panel_proxy_init (BusPanelProxy *panel); -static void bus_panel_proxy_real_destroy (BusPanelProxy *panel); - -static gboolean bus_panel_proxy_ibus_signal (IBusProxy *proxy, - IBusMessage *message); +static void bus_panel_proxy_real_destroy (IBusProxy *proxy); +static void bus_panel_proxy_g_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters); static void bus_panel_proxy_page_up (BusPanelProxy *panel); static void bus_panel_proxy_page_down (BusPanelProxy *panel); static void bus_panel_proxy_cursor_up (BusPanelProxy *panel); @@ -59,7 +84,6 @@ static void bus_panel_proxy_property_activate const gchar *prop_name, gint prop_state); - G_DEFINE_TYPE(BusPanelProxy, bus_panel_proxy, IBUS_TYPE_PROXY) BusPanelProxy * @@ -69,76 +93,73 @@ bus_panel_proxy_new (BusConnection *connection) GObject *obj; obj = g_object_new (BUS_TYPE_PANEL_PROXY, - "name", NULL, - "path", IBUS_PATH_PANEL, - "connection", connection, + "g-object-path", IBUS_PATH_PANEL, + "g-interface-name", "org.freedesktop.IBus.Panel", + "g-connection", bus_connection_get_dbus_connection (connection), NULL); return BUS_PANEL_PROXY (obj); } static void -bus_panel_proxy_class_init (BusPanelProxyClass *klass) +bus_panel_proxy_class_init (BusPanelProxyClass *class) { - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - IBusProxyClass *proxy_class = IBUS_PROXY_CLASS (klass); - - klass->page_up = bus_panel_proxy_page_up; - klass->page_down = bus_panel_proxy_page_down; - klass->cursor_up = bus_panel_proxy_cursor_up; - klass->cursor_down = bus_panel_proxy_cursor_down; + IBUS_PROXY_CLASS (class)->destroy = bus_panel_proxy_real_destroy; + G_DBUS_PROXY_CLASS (class)->g_signal = bus_panel_proxy_g_signal; - klass->candidate_clicked = bus_panel_proxy_candidate_clicked; - klass->property_activate = bus_panel_proxy_property_activate; + class->page_up = bus_panel_proxy_page_up; + class->page_down = bus_panel_proxy_page_down; + class->cursor_up = bus_panel_proxy_cursor_up; + class->cursor_down = bus_panel_proxy_cursor_down; + class->candidate_clicked = bus_panel_proxy_candidate_clicked; + class->property_activate = bus_panel_proxy_property_activate; - ibus_object_class->destroy = (IBusObjectDestroyFunc) bus_panel_proxy_real_destroy; - proxy_class->ibus_signal = bus_panel_proxy_ibus_signal; /* install signals */ panel_signals[PAGE_UP] = g_signal_new (I_("page-up"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(BusPanelProxyClass, page_up), NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); panel_signals[PAGE_DOWN] = g_signal_new (I_("page-down"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(BusPanelProxyClass, page_down), NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); panel_signals[CURSOR_UP] = g_signal_new (I_("cursor-up"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(BusPanelProxyClass, cursor_up), NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); panel_signals[CURSOR_DOWN] = g_signal_new (I_("cursor-down"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(BusPanelProxyClass, cursor_down), NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); panel_signals[CANDIDATE_CLICKED] = g_signal_new (I_("candidate-clicked"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(BusPanelProxyClass, candidate_clicked), NULL, NULL, - ibus_marshal_VOID__UINT_UINT_UINT, + bus_marshal_VOID__UINT_UINT_UINT, G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_UINT, @@ -146,32 +167,32 @@ bus_panel_proxy_class_init (BusPanelProxyClass *klass) panel_signals[PROPERTY_ACTIVATE] = g_signal_new (I_("property-activate"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(BusPanelProxyClass, property_activate), NULL, NULL, - ibus_marshal_VOID__STRING_INT, + bus_marshal_VOID__STRING_INT, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT); panel_signals[PROPERTY_SHOW] = g_signal_new (I_("property-show"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__STRING, + bus_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); panel_signals[PROPERTY_HIDE] = g_signal_new (I_("property-hide"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__STRING, + bus_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); @@ -184,36 +205,29 @@ bus_panel_proxy_init (BusPanelProxy *panel) } static void -bus_panel_proxy_real_destroy (BusPanelProxy *panel) +bus_panel_proxy_real_destroy (IBusProxy *proxy) { - if (ibus_proxy_get_connection ((IBusProxy *)panel) != NULL) { - ibus_proxy_call ((IBusProxy *) panel, - "Destroy", - G_TYPE_INVALID); - } + BusPanelProxy *panel = (BusPanelProxy *)proxy; if (panel->focused_context) { bus_panel_proxy_focus_out (panel, panel->focused_context); panel->focused_context = NULL; } - IBUS_OBJECT_CLASS(bus_panel_proxy_parent_class)->destroy (IBUS_OBJECT (panel)); + IBUS_PROXY_CLASS(bus_panel_proxy_parent_class)->destroy ((IBusProxy *)panel); } -static gboolean -bus_panel_proxy_ibus_signal (IBusProxy *proxy, - IBusMessage *message) +static void +bus_panel_proxy_g_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters) { - g_assert (BUS_IS_PANEL_PROXY (proxy)); - g_assert (message != NULL); - - BusPanelProxy *panel; - IBusError *error; - gint i; + BusPanelProxy *panel = (BusPanelProxy *)proxy; static const struct { - const gchar *member; - const guint signal_id; + const gchar *signal_name; + const guint signal_id; } signals [] = { { "PageUp", PAGE_UP }, { "PageDown", PAGE_DOWN }, @@ -221,78 +235,46 @@ bus_panel_proxy_ibus_signal (IBusProxy *proxy, { "CursorDown", CURSOR_DOWN }, }; - panel = BUS_PANEL_PROXY (proxy); - + gint i; for (i = 0; i < G_N_ELEMENTS (signals); i++) { - if (ibus_message_is_signal (message, IBUS_INTERFACE_PANEL, signals[i].member)) { + if (g_strcmp0 (signal_name, signals[i].signal_name) == 0) { g_signal_emit (panel, panel_signals[signals[i].signal_id], 0); - goto handled; + return; } } - if (ibus_message_is_signal (message, IBUS_INTERFACE_PANEL, "CandidateClicked")) { - guint index, button, state; - gboolean retval; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_UINT, &index, - G_TYPE_UINT, &button, - G_TYPE_UINT, &state, - G_TYPE_INVALID); - if (!retval) - goto failed; - + if (g_strcmp0 ("CandidateClicked", signal_name) == 0) { + guint index = 0; + guint button = 0; + guint state = 0; + g_variant_get (parameters, "(uuu)", &index, &button, &state); g_signal_emit (panel, panel_signals[CANDIDATE_CLICKED], 0, index, button, state); + return; } - else if (ibus_message_is_signal (message, IBUS_INTERFACE_PANEL, "PropertyActivate")) { - gchar *prop_name; - gint prop_state; - gboolean retval; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &prop_name, - G_TYPE_INT, &prop_state, - G_TYPE_INVALID); - if (!retval) - goto failed; + if (g_strcmp0 ("PropertyActivate", signal_name) == 0) { + gchar *prop_name = NULL; + gint prop_state = 0; + g_variant_get (parameters, "(&si)", &prop_name, &prop_state); g_signal_emit (panel, panel_signals[PROPERTY_ACTIVATE], 0, prop_name, prop_state); + return; } - else if (ibus_message_is_signal (message, IBUS_INTERFACE_PANEL, "PropertyShow")) { - gchar *prop_name; - gboolean retval; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &prop_name, - G_TYPE_INVALID); - if (!retval) - goto failed; + + if (g_strcmp0 ("PropertyShow", signal_name) == 0) { + gchar *prop_name = NULL; + g_variant_get (parameters, "(&s)", &prop_name); g_signal_emit (panel, panel_signals[PROPERTY_SHOW], 0, prop_name); + return; } - else if (ibus_message_is_signal (message, IBUS_INTERFACE_PANEL, "PropertyHide")) { - gchar *prop_name; - gboolean retval; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &prop_name, - G_TYPE_INVALID); - if (!retval) - goto failed; + + if (g_strcmp0 ("PropertyHide", signal_name) == 0) { + gchar *prop_name = NULL; + g_variant_get (parameters, "(&s)", &prop_name); g_signal_emit (panel, panel_signals[PROPERTY_HIDE], 0, prop_name); + return; } - -handled: - g_signal_stop_emission_by_name (panel, "ibus-signal"); - return TRUE; - -failed: - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - return FALSE; + /* shound not be reached */ + g_return_if_reached (); } @@ -305,14 +287,11 @@ bus_panel_proxy_set_cursor_location (BusPanelProxy *panel, gint h) { g_assert (BUS_IS_PANEL_PROXY (panel)); - - ibus_proxy_call ((IBusProxy *) panel, - "SetCursorLocation", - G_TYPE_INT, &x, - G_TYPE_INT, &y, - G_TYPE_INT, &w, - G_TYPE_INT, &h, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)panel, + "SetCursorLocation", + g_variant_new ("(iiii)", x, y, w, h), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); } void @@ -322,14 +301,14 @@ bus_panel_proxy_update_preedit_text (BusPanelProxy *panel, gboolean visible) { g_assert (BUS_IS_PANEL_PROXY (panel)); - g_assert (text != NULL); - - ibus_proxy_call ((IBusProxy *) panel, - "UpdatePreeditText", - IBUS_TYPE_TEXT, &text, - G_TYPE_UINT, &cursor_pos, - G_TYPE_BOOLEAN, &visible, - G_TYPE_INVALID); + g_assert (IBUS_IS_TEXT (text)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable* )text); + g_dbus_proxy_call ((GDBusProxy *)panel, + "UpdatePreeditText", + g_variant_new ("(vub)", variant, cursor_pos, visible), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); } void @@ -338,13 +317,14 @@ bus_panel_proxy_update_auxiliary_text (BusPanelProxy *panel, gboolean visible) { g_assert (BUS_IS_PANEL_PROXY (panel)); - g_assert (text != NULL); - - ibus_proxy_call ((IBusProxy *) panel, - "UpdateAuxiliaryText", - IBUS_TYPE_TEXT, &text, - G_TYPE_BOOLEAN, &visible, - G_TYPE_INVALID); + g_assert (IBUS_IS_TEXT (text)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable* )text); + g_dbus_proxy_call ((GDBusProxy *)panel, + "UpdateAuxiliaryText", + g_variant_new ("(vb)", variant, visible), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); } void @@ -353,13 +333,14 @@ bus_panel_proxy_update_lookup_table (BusPanelProxy *panel, gboolean visible) { g_assert (BUS_IS_PANEL_PROXY (panel)); - g_assert (table != NULL); - - ibus_proxy_call ((IBusProxy *) panel, - "UpdateLookupTable", - IBUS_TYPE_LOOKUP_TABLE, &table, - G_TYPE_BOOLEAN, &visible, - G_TYPE_INVALID); + g_assert (IBUS_IS_LOOKUP_TABLE (table)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable* )table); + g_dbus_proxy_call ((GDBusProxy *)panel, + "UpdateLookupTable", + g_variant_new ("(vb)", variant, visible), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); } void @@ -367,13 +348,14 @@ bus_panel_proxy_register_properties (BusPanelProxy *panel, IBusPropList *prop_list) { g_assert (BUS_IS_PANEL_PROXY (panel)); - g_assert (prop_list != NULL); - - ibus_proxy_call ((IBusProxy *) panel, - "RegisterProperties", - IBUS_TYPE_PROP_LIST, &prop_list, - G_TYPE_INVALID); - ibus_connection_flush (ibus_proxy_get_connection((IBusProxy *)panel)); + g_assert (IBUS_IS_PROP_LIST (prop_list)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)prop_list); + g_dbus_proxy_call ((GDBusProxy *)panel, + "RegisterProperties", + g_variant_new ("(v)", variant), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); } void @@ -381,12 +363,14 @@ bus_panel_proxy_update_property (BusPanelProxy *panel, IBusProperty *prop) { g_assert (BUS_IS_PANEL_PROXY (panel)); - g_assert (prop != NULL); - - ibus_proxy_call ((IBusProxy *) panel, - "UpdateProperty", - IBUS_TYPE_PROPERTY, &prop, - G_TYPE_INVALID); + g_assert (IBUS_IS_PROPERTY (prop)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)prop); + g_dbus_proxy_call ((GDBusProxy *)panel, + "UpdateProperty", + g_variant_new ("(v)", variant), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); } #define DEFINE_FUNC(name) \ @@ -438,9 +422,11 @@ bus_panel_proxy_property_activate (BusPanelProxy *panel, void bus_panel_proxy_##name (BusPanelProxy *panel) \ { \ g_assert (BUS_IS_PANEL_PROXY (panel)); \ - ibus_proxy_call ((IBusProxy *) panel, \ - #Name, \ - G_TYPE_INVALID); \ + g_dbus_proxy_call ((GDBusProxy *) panel, \ + #Name, \ + NULL, \ + G_DBUS_CALL_FLAGS_NONE, \ + -1, NULL, NULL, NULL); \ } DEFINE_FUNCTION (ShowPreeditText, show_preedit_text) @@ -640,12 +626,13 @@ bus_panel_proxy_focus_in (BusPanelProxy *panel, g_object_ref_sink (context); panel->focused_context = context; - const gchar *path = ibus_service_get_path ((IBusService *)context); + const gchar *path = ibus_service_get_object_path ((IBusService *)context); - ibus_proxy_call ((IBusProxy *) panel, - "FocusIn", - IBUS_TYPE_OBJECT_PATH, &path, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)panel, + "FocusIn", + g_variant_new ("(o)", path), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); /* install signal handlers */ gint i; @@ -674,12 +661,13 @@ bus_panel_proxy_focus_out (BusPanelProxy *panel, panel); } - const gchar *path = ibus_service_get_path ((IBusService *)context); + const gchar *path = ibus_service_get_object_path ((IBusService *)context); - ibus_proxy_call ((IBusProxy *) panel, - "FocusOut", - IBUS_TYPE_OBJECT_PATH, &path, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *)panel, + "FocusOut", + g_variant_new ("(o)", path), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); g_object_unref (panel->focused_context); panel->focused_context = NULL; diff --git a/bus/panelproxy.h b/bus/panelproxy.h index 648b995..83d6ff1 100644 --- a/bus/panelproxy.h +++ b/bus/panelproxy.h @@ -19,8 +19,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __PANEL_PROXY_H_ -#define __PANEL_PROXY_H_ +#ifndef __BUS_PANEL_PROXY_H_ +#define __BUS_PANEL_PROXY_H_ #include #include "connection.h" @@ -49,31 +49,6 @@ G_BEGIN_DECLS typedef struct _BusPanelProxy BusPanelProxy; typedef struct _BusPanelProxyClass BusPanelProxyClass; -struct _BusPanelProxy { - IBusProxy parent; - - /* instance members */ - BusInputContext *focused_context; -}; - -struct _BusPanelProxyClass { - IBusProxyClass parent; - /* class members */ - - void (* page_up) (BusPanelProxy *panel); - void (* page_down) (BusPanelProxy *panel); - void (* cursor_up) (BusPanelProxy *panel); - void (* cursor_down) (BusPanelProxy *panel); - void (* candidate_clicked) (BusPanelProxy *panel, - guint index, - guint button, - guint state); - - void (* property_activate) (BusPanelProxy *panel, - const gchar *prop_name, - gint prop_state); -}; - GType bus_panel_proxy_get_type (void); BusPanelProxy *bus_panel_proxy_new (BusConnection *connection); void bus_panel_proxy_focus_in (BusPanelProxy *panel, diff --git a/bus/registry.c b/bus/registry.c index 03d306a..8532c5d 100644 --- a/bus/registry.c +++ b/bus/registry.c @@ -19,13 +19,14 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ +#include "registry.h" #include #include #include #include -#include -#include "registry.h" +#include "types.h" #include "option.h" +#include "marshalers.h" enum { CHANGED, @@ -58,7 +59,7 @@ bus_registry_class_init (BusRegistryClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + bus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -586,7 +587,7 @@ bus_registry_name_owner_changed (BusRegistry *registry, factory = bus_factory_proxy_get_from_component (component); if (factory != NULL) { - ibus_object_destroy ((IBusObject *)factory); + ibus_proxy_destroy ((IBusProxy *)factory); } } diff --git a/bus/registry.h b/bus/registry.h index 7691429..5456841 100644 --- a/bus/registry.h +++ b/bus/registry.h @@ -19,8 +19,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __REGISTRY_H_ -#define __REGISTRY_H_ +#ifndef __BUS_REGISTRY_H_ +#define __BUS_REGISTRY_H_ #include #include "factoryproxy.h" diff --git a/bus/server.c b/bus/server.c index 5af6dbf..2e9d6ce 100644 --- a/bus/server.c +++ b/bus/server.c @@ -19,140 +19,87 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include -#include -#include -#include -#include - #include "server.h" -#include "connection.h" +#include #include "dbusimpl.h" #include "ibusimpl.h" +#include "option.h" -/* functions prototype */ -static void bus_server_destroy (BusServer *server); -static void bus_server_new_connection - (BusServer *server, - BusConnection *connection); - -G_DEFINE_TYPE (BusServer, bus_server, IBUS_TYPE_SERVER) +static GDBusServer *server = NULL; +static GMainLoop *mainloop = NULL; +static BusDBusImpl *dbus = NULL; +static BusIBusImpl *ibus = NULL; -static void -bus_server_class_init (BusServerClass *klass) +static gboolean +bus_new_connection_cb (GDBusServer *server, + GDBusConnection *dbus_connection, + gpointer user_data) { - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); + BusConnection *connection = bus_connection_new (dbus_connection); + bus_dbus_impl_new_connection (dbus, connection); - ibus_object_class->destroy = (IBusObjectDestroyFunc) bus_server_destroy; - - IBUS_SERVER_CLASS (klass)->new_connection = - (IBusNewConnectionFunc) bus_server_new_connection; -} - -BusServer * -bus_server_get_default (void) -{ - static BusServer *server = NULL; - - if (server == NULL) { - server = (BusServer *) g_object_new (BUS_TYPE_SERVER, - "connection-type", BUS_TYPE_CONNECTION, - NULL); - bus_dbus_impl_get_default (); - bus_ibus_impl_get_default (); + if (g_object_is_floating (connection)) { + ibus_object_destroy ((IBusObject *)connection); + g_object_unref (connection); } - return server; + return TRUE; } -gboolean -bus_server_listen (BusServer *server) +void +bus_server_init (void) { - g_assert (BUS_IS_SERVER (server)); + dbus = bus_dbus_impl_get_default (); + ibus = bus_ibus_impl_get_default (); + bus_dbus_impl_register_object (dbus, (IBusService *)ibus); - const gchar *mechanisms[] = { - "EXTERNAL", - NULL - }; + /* init server */ + GDBusServerFlags flags = G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS; + gchar *guid = g_dbus_generate_guid (); + server = g_dbus_server_new_sync (g_address, + flags, guid, NULL, NULL, NULL); + g_free (guid); - const gchar *address = "unix:tmpdir=/tmp/"; - gboolean retval; + g_signal_connect (server, "new-connection", G_CALLBACK (bus_new_connection_cb), NULL); -#if 0 - path = ibus_get_socket_folder (); - mkdir (path, 0700); - chmod (path, 0700); + g_dbus_server_start (server); - address = ibus_get_address (); -#endif + gchar *address = g_strdup_printf ("%s,guid=%s", + g_dbus_server_get_client_address (server), + g_dbus_server_get_guid (server)); - retval = ibus_server_listen (IBUS_SERVER (server), address); + /* write address to file */ + g_debug ("address = %s", address); -#if 0 - chmod (ibus_get_socket_path (), 0600); + /* FIXME */ +#if 1 + ibus_write_address (address); #endif - ibus_server_set_auth_mechanisms ((IBusServer *)server, mechanisms); - - if (!retval) { -#if 0 - g_printerr ("Can not listen on %s! Please try remove directory %s and run again.", address, path); -#else - g_printerr ("Can not listen on %s!", address); -#endif - exit (-1); - } - - ibus_write_address (ibus_server_get_address (IBUS_SERVER (server))); - - return retval; + g_free (address); } void -bus_server_run (BusServer *server) +bus_server_run (void) { - g_assert (BUS_IS_SERVER (server)); + /* create main loop */ + mainloop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (mainloop); - g_main_loop_run (server->loop); -} + /* stop server */ + g_dbus_server_stop (server); -void -bus_server_quit (BusServer *server) -{ - g_assert (BUS_IS_SERVER (server)); + ibus_object_destroy ((IBusObject *)dbus); + ibus_object_destroy ((IBusObject *)ibus); - g_main_loop_quit (server->loop); + /* release resources */ + g_object_unref (server); + g_main_loop_unref (mainloop); + mainloop = NULL; } -static void -bus_server_init (BusServer *server) -{ - server->loop = g_main_loop_new (NULL, FALSE); - server->dbus = bus_dbus_impl_get_default (); - server->ibus = bus_ibus_impl_get_default (); -} - -static void -bus_server_new_connection (BusServer *server, - BusConnection *connection) -{ - g_assert (BUS_IS_SERVER (server)); - bus_dbus_impl_new_connection (server->dbus, connection); -} - -static void -bus_server_destroy (BusServer *server) +void +bus_server_quit (void) { - g_assert (BUS_IS_SERVER (server)); - - ibus_object_destroy ((IBusObject *) server->dbus); - g_object_unref (server->dbus); - ibus_object_destroy ((IBusObject *) server->ibus); - g_object_unref (server->ibus); - - while (g_main_loop_is_running (server->loop)) { - g_main_loop_quit (server->loop); - } - g_main_loop_unref (server->loop); - - IBUS_OBJECT_CLASS (bus_server_parent_class)->destroy (IBUS_OBJECT (server)); + if (mainloop) + g_main_loop_quit (mainloop); } diff --git a/bus/server.h b/bus/server.h index fcd8a18..c7d9282 100644 --- a/bus/server.h +++ b/bus/server.h @@ -19,60 +19,16 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef __SERVER_H_ -#define __SERVER_H_ +#ifndef __BUS_SERVER_H_ +#define __BUS_SERVER_H_ #include -#include "dbusimpl.h" -#include "ibusimpl.h" - -/* - * Type macros. - */ - -/* define GOBJECT macros */ -#define BUS_TYPE_SERVER \ - (bus_server_get_type ()) -#define BUS_SERVER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), BUS_TYPE_SERVER, BusServer)) -#define BUS_SERVER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), BUS_TYPE_SERVER, BusServerClass)) -#define BUS_IS_SERVER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BUS_TYPE_SERVER)) -#define BUS_IS_SERVER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), BUS_TYPE_SERVER)) -#define BUS_SERVER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), BUS_TYPE_SERVER, BusServerClass)) -#define BUS_DEFAULT_SERVER \ - (bus_server_get_default ()) G_BEGIN_DECLS -typedef struct _BusServer BusServer; -typedef struct _BusServerClass BusServerClass; - -struct _BusServer { - IBusServer parent; - - /* instance members */ - GMainLoop *loop; - - BusDBusImpl *dbus; - BusIBusImpl *ibus; - -}; - -struct _BusServerClass { - IBusServerClass parent; - - /* class members */ -}; - -GType bus_server_get_type (void); -BusServer *bus_server_get_default (void); -gboolean bus_server_listen (BusServer *server); -void bus_server_run (BusServer *server); -void bus_server_quit (BusServer *server); +void bus_server_init (void); +void bus_server_run (void); +void bus_server_quit (void); G_END_DECLS #endif diff --git a/bus/test-matchrule.c b/bus/test-matchrule.c index c3dc233..6713ba5 100644 --- a/bus/test-matchrule.c +++ b/bus/test-matchrule.c @@ -1,5 +1,4 @@ /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ -#include #include "matchrule.h" int diff --git a/bus/types.h b/bus/types.h new file mode 100644 index 0000000..efb914f --- /dev/null +++ b/bus/types.h @@ -0,0 +1,30 @@ +/* vim:set et sts=4: */ +/* ibus - The Input Bus + * Copyright (C) 2008-2010 Peng Huang + * Copyright (C) 2008-2010 Red Hat, Inc. + * Copyright (c) 2010 Google, Inc. + * + * 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. + */ +#ifndef __BUS_TYPES_H_ +#define __BUS_TYPES_H_ + +#include + +#define I_(string) g_intern_static_string (string) + +#endif + diff --git a/client/gtk2/Makefile.am b/client/gtk2/Makefile.am index 8fb3d30..d782af2 100644 --- a/client/gtk2/Makefile.am +++ b/client/gtk2/Makefile.am @@ -20,7 +20,7 @@ # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA -libibus = $(top_builddir)/src/libibus.la +libibus = $(top_builddir)/src/libibus-2.0.la INCLUDES = \ -I$(top_srcdir)/src \ diff --git a/client/gtk2/ibusim.c b/client/gtk2/ibusim.c index 3a3510d..11286d1 100644 --- a/client/gtk2/ibusim.c +++ b/client/gtk2/ibusim.c @@ -52,7 +52,7 @@ im_module_init (GTypeModule *type_module) { /* make module resident */ g_type_module_use (type_module); - + ibus_init (); ibus_im_context_register_type (type_module); } diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c index c06faaa..fd91015 100644 --- a/client/gtk2/ibusimcontext.c +++ b/client/gtk2/ibusimcontext.c @@ -443,7 +443,7 @@ ibus_im_context_finalize (GObject *obj) g_signal_handlers_disconnect_by_func (_bus, G_CALLBACK (_bus_connected_cb), obj); if (ibusimcontext->ibuscontext) { - ibus_object_destroy ((IBusObject *)ibusimcontext->ibuscontext); + ibus_proxy_destroy ((IBusProxy *)ibusimcontext->ibuscontext); } ibus_im_context_set_client_window ((GtkIMContext *)ibusimcontext, NULL); @@ -1089,6 +1089,7 @@ _create_input_context (IBusIMContext *ibusimcontext) g_assert (ibusimcontext->ibuscontext == NULL); + g_debug ("create ibus context"); ibusimcontext->ibuscontext = ibus_bus_create_input_context (_bus, "gtk-im"); g_return_if_fail (ibusimcontext->ibuscontext != NULL); diff --git a/client/gtk3/Makefile.am b/client/gtk3/Makefile.am index ac757e3..e9584bc 100644 --- a/client/gtk3/Makefile.am +++ b/client/gtk3/Makefile.am @@ -20,7 +20,7 @@ # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA -libibus = $(top_builddir)/src/libibus.la +libibus = $(top_builddir)/src/libibus-2.0.la INCLUDES = \ -I$(top_srcdir)/src \ diff --git a/client/x11/Makefile.am b/client/x11/Makefile.am index 1910883..b460236 100644 --- a/client/x11/Makefile.am +++ b/client/x11/Makefile.am @@ -22,7 +22,7 @@ libIMdkit = $(top_builddir)/util/IMdkit/libIMdkit.la -libibus = $(top_builddir)/src/libibus.la +libibus = $(top_builddir)/src/libibus-2.0.la libexec_PROGRAMS = ibus-x11 diff --git a/configure.ac b/configure.ac index 4f64cb6..cf76df7 100644 --- a/configure.ac +++ b/configure.ac @@ -21,10 +21,10 @@ # Boston, MA 02111-1307 USA # if not 1, append datestamp to the version number. -m4_define([ibus_released], [1]) +m4_define([ibus_released], [0]) m4_define([ibus_major_version], [1]) m4_define([ibus_minor_version], [3]) -m4_define([ibus_micro_version], [8]) +m4_define([ibus_micro_version], [99]) m4_define(ibus_maybe_datestamp, m4_esyscmd([if test x]ibus_released[ != x1; then date +.%Y%m%d | tr -d '\n\r'; fi])) @@ -61,7 +61,7 @@ AC_SUBST(DATE_DISPLAY) # If only source code changed, lt_revision + 1 # If any interface added, lt_age + 1 # If any interfaces changed or removed, lt_current + 1, lt_revision = 0, lt_age = 0 -m4_define([lt_current], [2]) +m4_define([lt_current], [0]) m4_define([lt_revision], [0]) m4_define([lt_age], [0]) LT_VERSION_INFO="lt_current:lt_revision:lt_age" @@ -76,16 +76,16 @@ AC_CHECK_FUNCS(daemon) # check glib2 AM_PATH_GLIB_2_0 PKG_CHECK_MODULES(GLIB2, [ - glib-2.0 >= 2.18 + glib-2.0 >= 2.25 ]) PKG_CHECK_MODULES(GOBJECT2, [ - gobject-2.0 >= 2.18 + gobject-2.0 >= 2.25 ]) PKG_CHECK_MODULES(GIO2, [ - gio-2.0 >= 2.18 + gio-2.0 >= 2.25 ]) PKG_CHECK_MODULES(GTHREAD2, [ - gthread-2.0 >= 2.18 + gthread-2.0 >= 2.25 ]) AC_ARG_ENABLE(gtk2, @@ -188,7 +188,8 @@ GTK_DOC_CHECK(1.9) if test x"$enable_gtk_doc" = x"no"; then enable_gtk_doc="no (disabled, use --enable-gtk-doc to enable)" fi -# check for dbus-glib + +# check for dbus PKG_CHECK_MODULES(DBUS, [ dbus-1 ]) @@ -199,7 +200,7 @@ AC_ARG_ENABLE(gconf, [enable_gconf=$enableval], [enable_gconf=yes] ) -AM_CONDITIONAL([ENABLE_GCONF], [test "x$enable_gconf" = "xyes"]) +AM_CONDITIONAL([ENABLE_GCONF], [test x"$enable_gconf" = x"yes"]) if test x"$enable_gconf" = x"yes"; then # check gconf @@ -238,7 +239,8 @@ AC_ARG_ENABLE(python, [enable_python=yes] ) -AM_CONDITIONAL([ENABLE_PYTHON], [test "x$enable_python" = "xyes"]) +AM_CONDITIONAL([ENABLE_PYTHON], [test x"$enable_python" = x"yes"]) +AM_CONDITIONAL([ENABLE_DAEMON], [true]) if test x"$enable_python" = x"yes"; then # check python @@ -345,7 +347,7 @@ AC_SUBST(ISOCODES_PREFIX) # OUTPUT files AC_CONFIG_FILES([ po/Makefile.in Makefile -ibus-1.0.pc +ibus-2.0.pc ibus.spec xinput-ibus memconf/Makefile @@ -356,6 +358,7 @@ client/gtk3/Makefile client/x11/Makefile src/Makefile src/ibusversion.h +src/tests/Makefile bus/Makefile util/Makefile util/IMdkit/Makefile @@ -389,6 +392,7 @@ Build options: Install prefix $prefix Build shared libs $enable_shared Build static libs $enable_static + CFLAGS $CFLAGS Gtk2 immodule dir $GTK2_IM_MODULEDIR Gtk3 immodule dir $GTK3_IM_MODULEDIR Build gtk2 immodule $enable_gtk2 diff --git a/debian/libibus-dev.install b/debian/libibus-dev.install index 51e89e7..34eb19e 100644 --- a/debian/libibus-dev.install +++ b/debian/libibus-dev.install @@ -1,6 +1,6 @@ debian/tmp/usr/include/* -debian/tmp/usr/lib/libibus.so -debian/tmp/usr/lib/libibus.a +debian/tmp/usr/lib/libibus-*.so +debian/tmp/usr/lib/libibus-*.a debian/tmp/usr/lib/pkgconfig/* debian/tmp/usr/share/gir-1.0/* debian/tmp/usr/share/vala/vapi/* diff --git a/debian/libibus2.install b/debian/libibus2.install index 15c8243..b6fcee9 100644 --- a/debian/libibus2.install +++ b/debian/libibus2.install @@ -1,2 +1,2 @@ -debian/tmp/usr/lib/libibus.so.2* +debian/tmp/usr/lib/libibus-*.so.* debian/tmp/usr/lib/girepository-1.0/* diff --git a/debian/libibus2.symbols b/debian/libibus2.symbols index c94c871..9214f81 100644 --- a/debian/libibus2.symbols +++ b/debian/libibus2.symbols @@ -1,4 +1,4 @@ -libibus.so.2 libibus2 #MINVER# +libibus-2.0.so.0 libibus2 #MINVER# ibus_attr_background_new@Base 1.2.99.20100202 ibus_attr_foreground_new@Base 1.2.99.20100202 ibus_attr_list_append@Base 1.2.99.20100202 @@ -11,9 +11,6 @@ libibus.so.2 libibus2 #MINVER# ibus_attribute_get_type@Base 1.2.99.20100202 ibus_attribute_new@Base 1.2.99.20100202 ibus_bus_add_match@Base 1.2.99.20100202 - ibus_bus_call@Base 1.3.5.20100705 - ibus_bus_call_with_reply@Base 1.3.5.20100705 - ibus_bus_call_with_reply_valist@Base 1.3.5.20100705 ibus_bus_create_input_context@Base 1.2.99.20100202 ibus_bus_current_input_context@Base 1.2.99.20100202 ibus_bus_exit@Base 1.2.99.20100202 @@ -62,33 +59,10 @@ libibus.so.2 libibus2 #MINVER# ibus_config_service_value_changed@Base 1.2.99.20100202 ibus_config_set_value@Base 1.2.99.20100202 ibus_config_unset@Base 1.2.99.20100202 - ibus_connection_call@Base 1.2.99.20100202 - ibus_connection_call_with_reply@Base 1.3.5.20100705 - ibus_connection_close@Base 1.2.99.20100202 - ibus_connection_flush@Base 1.2.99.20100202 - ibus_connection_get_connection@Base 1.2.99.20100202 - ibus_connection_get_type@Base 1.2.99.20100202 - ibus_connection_get_unix_user@Base 1.2.99.20100202 - ibus_connection_is_authenticated@Base 1.2.99.20100202 - ibus_connection_is_connected@Base 1.2.99.20100202 - ibus_connection_new@Base 1.2.99.20100202 - ibus_connection_open@Base 1.2.99.20100202 - ibus_connection_open_private@Base 1.2.99.20100202 - ibus_connection_read_write_dispatch@Base 1.2.99.20100202 - ibus_connection_register_object_path@Base 1.2.99.20100202 - ibus_connection_send@Base 1.2.99.20100202 - ibus_connection_send_signal@Base 1.2.99.20100202 - ibus_connection_send_signal_valist@Base 1.2.99.20100202 - ibus_connection_send_valist@Base 1.2.99.20100202 - ibus_connection_send_with_reply@Base 1.2.99.20100202 - ibus_connection_send_with_reply_and_block@Base 1.2.99.20100202 - ibus_connection_set_connection@Base 1.2.99.20100202 - ibus_connection_unregister_object_path@Base 1.2.99.20100202 - ibus_dbus_connection_setup@Base 1.2.99.20100202 - ibus_dbus_server_setup@Base 1.2.99.20100202 ibus_engine_commit_text@Base 1.2.99.20100202 ibus_engine_delete_surrounding_text@Base 1.2.99.20100202 ibus_engine_desc_get_type@Base 1.2.99.20100202 + ibus_engine_desc_new2@Base 1.9.0.20101013 ibus_engine_desc_new@Base 1.2.99.20100202 ibus_engine_desc_new_from_xml_node@Base 1.2.99.20100202 ibus_engine_desc_output@Base 1.2.99.20100202 @@ -99,6 +73,7 @@ libibus.so.2 libibus2 #MINVER# ibus_engine_hide_lookup_table@Base 1.2.99.20100202 ibus_engine_hide_preedit_text@Base 1.2.99.20100202 ibus_engine_new@Base 1.2.99.20100202 + ibus_engine_new_type@Base 1.9.0.20101013 ibus_engine_register_properties@Base 1.2.99.20100202 ibus_engine_show_auxiliary_text@Base 1.2.99.20100202 ibus_engine_show_lookup_table@Base 1.2.99.20100202 @@ -109,11 +84,6 @@ libibus.so.2 libibus2 #MINVER# ibus_engine_update_preedit_text@Base 1.2.99.20100202 ibus_engine_update_preedit_text_with_mode@Base 1.3.0 ibus_engine_update_property@Base 1.2.99.20100202 - ibus_error_free@Base 1.2.99.20100202 - ibus_error_new@Base 1.2.99.20100202 - ibus_error_new_from_message@Base 1.2.99.20100202 - ibus_error_new_from_printf@Base 1.2.99.20100202 - ibus_error_new_from_text@Base 1.2.99.20100202 ibus_factory_add_engine@Base 1.2.99.20100202 ibus_factory_get_type@Base 1.2.99.20100202 ibus_factory_new@Base 1.2.99.20100202 @@ -129,6 +99,7 @@ libibus.so.2 libibus2 #MINVER# ibus_hotkey_profile_add_hotkey_from_string@Base 1.2.99.20100202 ibus_hotkey_profile_filter_key_event@Base 1.2.99.20100202 ibus_hotkey_profile_get_type@Base 1.2.99.20100202 + ibus_hotkey_profile_lookup_hotkey@Base 1.9.0.20101013 ibus_hotkey_profile_new@Base 1.2.99.20100202 ibus_hotkey_profile_remove_hotkey@Base 1.2.99.20100202 ibus_hotkey_profile_remove_hotkey_by_event@Base 1.2.99.20100202 @@ -188,72 +159,6 @@ libibus.so.2 libibus2 #MINVER# ibus_lookup_table_set_page_size@Base 1.2.99.20100202 ibus_lookup_table_set_round@Base 1.2.99.20100202 ibus_main@Base 1.2.99.20100202 - ibus_mainloop_setup@Base 1.2.99.20100202 - ibus_marshal_BOOLEAN__POINTER@Base 1.2.99.20100202 - ibus_marshal_BOOLEAN__POINTER_POINTER@Base 1.2.99.20100202 - ibus_marshal_BOOLEAN__UINT_UINT@Base 1.2.99.20100202 - ibus_marshal_BOOLEAN__UINT_UINT_UINT@Base 1.2.99.20100202 - ibus_marshal_BOOLEAN__ULONG@Base 1.2.99.20100202 - ibus_marshal_VOID__BOXED_BOOLEAN@Base 1.2.99.20100202 - ibus_marshal_VOID__INT_INT_INT_INT@Base 1.2.99.20100202 - ibus_marshal_VOID__INT_UINT@Base 1.2.99.20100202 - ibus_marshal_VOID__OBJECT_BOOLEAN@Base 1.2.99.20100202 - ibus_marshal_VOID__OBJECT_UINT_BOOLEAN@Base 1.2.99.20100202 - ibus_marshal_VOID__OBJECT_UINT_BOOLEAN_UINT@Base 1.3.5.20100705 - ibus_marshal_VOID__STRING_INT@Base 1.2.99.20100202 - ibus_marshal_VOID__STRING_STRING_BOXED@Base 1.2.99.20100202 - ibus_marshal_VOID__STRING_STRING_STRING@Base 1.2.99.20100202 - ibus_marshal_VOID__STRING_UINT@Base 1.2.99.20100202 - ibus_marshal_VOID__UINT_UINT@Base 1.2.99.20100202 - ibus_marshal_VOID__UINT_UINT_UINT@Base 1.2.99.20100202 - ibus_message_append_args@Base 1.2.99.20100202 - ibus_message_append_args_valist@Base 1.2.99.20100202 - ibus_message_get_args@Base 1.2.99.20100202 - ibus_message_get_args_valist@Base 1.2.99.20100202 - ibus_message_get_destination@Base 1.2.99.20100202 - ibus_message_get_error_message@Base 1.2.99.20100202 - ibus_message_get_error_name@Base 1.2.99.20100202 - ibus_message_get_interface@Base 1.2.99.20100202 - ibus_message_get_member@Base 1.2.99.20100202 - ibus_message_get_no_reply@Base 1.2.99.20100202 - ibus_message_get_path@Base 1.2.99.20100202 - ibus_message_get_reply_serial@Base 1.2.99.20100202 - ibus_message_get_sender@Base 1.2.99.20100202 - ibus_message_get_serial@Base 1.2.99.20100202 - ibus_message_get_type@Base 1.2.99.20100202 - ibus_message_is_error@Base 1.2.99.20100202 - ibus_message_is_method_call@Base 1.2.99.20100202 - ibus_message_is_signal@Base 1.2.99.20100202 - ibus_message_iter_append@Base 1.2.99.20100202 - ibus_message_iter_close_container@Base 1.2.99.20100202 - ibus_message_iter_copy_data@Base 1.2.99.20100202 - ibus_message_iter_get@Base 1.2.99.20100202 - ibus_message_iter_get_arg_type@Base 1.2.99.20100202 - ibus_message_iter_get_basic@Base 1.2.99.20100202 - ibus_message_iter_get_element_type@Base 1.2.99.20100202 - ibus_message_iter_has_next@Base 1.2.99.20100202 - ibus_message_iter_init@Base 1.2.99.20100202 - ibus_message_iter_init_append@Base 1.2.99.20100202 - ibus_message_iter_next@Base 1.2.99.20100202 - ibus_message_iter_open_container@Base 1.2.99.20100202 - ibus_message_iter_recurse@Base 1.2.99.20100202 - ibus_message_new@Base 1.2.99.20100202 - ibus_message_new_error@Base 1.2.99.20100202 - ibus_message_new_error_printf@Base 1.2.99.20100202 - ibus_message_new_method_call@Base 1.2.99.20100202 - ibus_message_new_method_return@Base 1.2.99.20100202 - ibus_message_new_signal@Base 1.2.99.20100202 - ibus_message_ref@Base 1.2.99.20100202 - ibus_message_set_destination@Base 1.2.99.20100202 - ibus_message_set_error_name@Base 1.2.99.20100202 - ibus_message_set_interface@Base 1.2.99.20100202 - ibus_message_set_member@Base 1.2.99.20100202 - ibus_message_set_no_reply@Base 1.2.99.20100202 - ibus_message_set_path@Base 1.2.99.20100202 - ibus_message_set_reply_serial@Base 1.2.99.20100202 - ibus_message_set_sender@Base 1.2.99.20100202 - ibus_message_to_string@Base 1.2.99.20100202 - ibus_message_unref@Base 1.2.99.20100202 ibus_modifier_type_get_type@Base 1.2.99.20100202 ibus_object_destroy@Base 1.2.99.20100202 ibus_object_flags_get_type@Base 1.2.99.20100202 @@ -276,18 +181,6 @@ libibus.so.2 libibus2 #MINVER# ibus_panel_service_property_active@Base 1.2.99.20100202 ibus_panel_service_property_hide@Base 1.2.99.20100202 ibus_panel_service_property_show@Base 1.2.99.20100202 - ibus_pending_call_allocate_data_slot@Base 1.2.99.20100202 - ibus_pending_call_block@Base 1.2.99.20100202 - ibus_pending_call_cancel@Base 1.2.99.20100202 - ibus_pending_call_free_data_slot@Base 1.2.99.20100202 - ibus_pending_call_get_completed@Base 1.2.99.20100202 - ibus_pending_call_get_data@Base 1.2.99.20100202 - ibus_pending_call_ref@Base 1.2.99.20100202 - ibus_pending_call_set_data@Base 1.2.99.20100202 - ibus_pending_call_set_notify@Base 1.2.99.20100202 - ibus_pending_call_steal_reply@Base 1.2.99.20100202 - ibus_pending_call_unref@Base 1.2.99.20100202 - ibus_pending_call_wait@Base 1.2.99.20100202 ibus_preedit_focus_mode_get_type@Base 1.3.0 ibus_prop_list_append@Base 1.2.99.20100202 ibus_prop_list_get@Base 1.2.99.20100202 @@ -306,18 +199,8 @@ libibus.so.2 libibus2 #MINVER# ibus_property_set_tooltip@Base 1.2.99.20100202 ibus_property_set_visible@Base 1.2.99.20100202 ibus_property_update@Base 1.2.99.20100202 - ibus_proxy_call@Base 1.2.99.20100202 - ibus_proxy_call_with_reply@Base 1.2.99.20100202 - ibus_proxy_call_with_reply_and_block@Base 1.2.99.20100202 - ibus_proxy_get_connection@Base 1.2.99.20100202 - ibus_proxy_get_interface@Base 1.2.99.20100202 - ibus_proxy_get_name@Base 1.2.99.20100202 - ibus_proxy_get_path@Base 1.2.99.20100202 + ibus_proxy_destroy@Base 1.9.0.20101013 ibus_proxy_get_type@Base 1.2.99.20100202 - ibus_proxy_get_unique_name@Base 1.2.99.20100202 - ibus_proxy_handle_signal@Base 1.2.99.20100202 - ibus_proxy_new@Base 1.2.99.20100202 - ibus_proxy_send@Base 1.2.99.20100202 ibus_quit@Base 1.2.99.20100202 ibus_serializable_copy@Base 1.2.99.20100202 ibus_serializable_deserialize@Base 1.2.99.20100202 @@ -327,24 +210,16 @@ libibus.so.2 libibus2 #MINVER# ibus_serializable_remove_qattachment@Base 1.2.99.20100202 ibus_serializable_serialize@Base 1.2.99.20100202 ibus_serializable_set_qattachment@Base 1.2.99.20100202 - ibus_server_disconnect@Base 1.2.99.20100202 - ibus_server_get_address@Base 1.2.99.20100202 - ibus_server_get_id@Base 1.2.99.20100202 - ibus_server_get_type@Base 1.2.99.20100202 - ibus_server_is_connected@Base 1.2.99.20100202 - ibus_server_listen@Base 1.2.99.20100202 - ibus_server_new@Base 1.2.99.20100202 - ibus_server_set_auth_mechanisms@Base 1.2.99.20100202 - ibus_service_add_to_connection@Base 1.2.99.20100202 - ibus_service_get_connections@Base 1.2.99.20100202 - ibus_service_get_path@Base 1.2.99.20100202 + ibus_service_class_add_interfaces@Base 1.9.0.20101013 + ibus_service_emit_signal@Base 1.9.0.20101013 + ibus_service_get_connection@Base 1.9.0.20101013 + ibus_service_get_object_path@Base 1.9.0.20101013 ibus_service_get_type@Base 1.2.99.20100202 - ibus_service_handle_message@Base 1.2.99.20100202 ibus_service_new@Base 1.2.99.20100202 - ibus_service_remove_from_all_connections@Base 1.2.99.20100202 - ibus_service_remove_from_connection@Base 1.2.99.20100202 - ibus_service_send_signal@Base 1.2.99.20100202 + ibus_service_register@Base 1.9.0.20101013 + ibus_service_unregister@Base 1.9.0.20101013 ibus_set_display@Base 1.2.99.20100202 + ibus_set_log_handler@Base 1.9.0.20101013 ibus_text_append_attribute@Base 1.2.99.20100202 ibus_text_get_length@Base 1.2.99.20100202 ibus_text_get_type@Base 1.2.99.20100202 @@ -353,11 +228,6 @@ libibus.so.2 libibus2 #MINVER# ibus_text_new_from_string@Base 1.2.99.20100202 ibus_text_new_from_ucs4@Base 1.2.99.20100202 ibus_text_new_from_unichar@Base 1.2.99.20100202 - ibus_type_get_array@Base 1.2.99.20100202 - ibus_type_get_dict_entry@Base 1.2.99.20100202 - ibus_type_get_object_path@Base 1.2.99.20100202 - ibus_type_get_struct@Base 1.2.99.20100202 - ibus_type_get_variant@Base 1.2.99.20100202 ibus_write_address@Base 1.2.99.20100202 ibus_xml_free@Base 1.2.99.20100202 ibus_xml_output@Base 1.3.5.20100705 diff --git a/debian/rules b/debian/rules index a8b8836..84f7517 100755 --- a/debian/rules +++ b/debian/rules @@ -13,7 +13,7 @@ build: patch install: dh $@ --until auto_install - rm -rf $(CURDIR)/debian/tmp/usr/lib/libibus.la \ + rm -rf $(CURDIR)/debian/tmp/usr/lib/libibus*.la \ $(CURDIR)/debian/tmp/usr/lib/gtk-2.0/2.10.0/immodules/im-ibus.a \ $(CURDIR)/debian/tmp/usr/lib/gtk-2.0/2.10.0/immodules/im-ibus.la \ $(CURDIR)/debian/tmp/etc/xdg \ diff --git a/docs/reference/ibus/Makefile.am b/docs/reference/ibus/Makefile.am index 288e34d..420045a 100644 --- a/docs/reference/ibus/Makefile.am +++ b/docs/reference/ibus/Makefile.am @@ -94,7 +94,7 @@ INCLUDES = \ -I$(top_builddir)/src \ $(NULL) GTKDOC_LIBS = \ - $(top_builddir)/src/libibus.la \ + $(top_builddir)/src/libibus-2.0.la \ $(NULL) # This includes the standard gtk-doc make rules, copied by gtkdocize. diff --git a/docs/reference/ibus/ibus-sections.txt b/docs/reference/ibus/ibus-sections.txt index a5a6225..b8cc06f 100644 --- a/docs/reference/ibus/ibus-sections.txt +++ b/docs/reference/ibus/ibus-sections.txt @@ -8,13 +8,13 @@ ibus_prop_list_append ibus_prop_list_get ibus_prop_list_update_property -IBUS_PROP_LIST -IBUS_IS_PROP_LIST -IBUS_TYPE_PROP_LIST -ibus_prop_list_get_type -IBUS_PROP_LIST_CLASS -IBUS_IS_PROP_LIST_CLASS -IBUS_PROP_LIST_GET_CLASS +IBUS_COMPONENT +IBUS_IS_COMPONENT +IBUS_TYPE_COMPONENT +ibus_component_get_type +IBUS_COMPONENT_CLASS +IBUS_IS_COMPONENT_CLASS +IBUS_COMPONENT_GET_CLASS
@@ -42,6 +42,7 @@ IBUS_CONFIG_GET_CLASS IBUS_OBJECT_DESTROYED IBusObject IBusObjectClass +IBusObjectPrivate ibus_object_new ibus_object_destroy @@ -59,6 +60,7 @@ IBUS_OBJECT_GET_CLASS IBusBus IBusBus IBusBusClass +IBusBusPrivate ibus_bus_new ibus_bus_is_connected ibus_bus_hello @@ -94,6 +96,7 @@ IBUS_BUS_GET_CLASS IBusComponent IBusComponent IBusComponentClass +IBusComponentPrivate ibus_component_new ibus_component_new_from_xml_node ibus_component_new_from_file @@ -108,14 +111,60 @@ ibus_component_stop ibus_component_is_running ibus_component_get_from_engine ibus_component_set_restart +>>>>>>> wip. -IBUS_COMPONENT -IBUS_IS_COMPONENT -IBUS_TYPE_COMPONENT -ibus_component_get_type -IBUS_COMPONENT_CLASS -IBUS_IS_COMPONENT_CLASS -IBUS_COMPONENT_GET_CLASS +IBUS_KEYMAP +IBUS_IS_KEYMAP +IBUS_TYPE_KEYMAP +ibus_keymap_get_type +IBUS_KEYMAP_CLASS +IBUS_IS_KEYMAP_CLASS +IBUS_KEYMAP_GET_CLASS +
+ +
+ibusattribute +IBusAttribute +IBusAttrType +IBusAttrUnderline +IBusAttribute +IBusAttributeClass +ibus_attribute_new +ibus_attr_underline_new +ibus_attr_foreground_new +ibus_attr_background_new + +IBUS_ATTRIBUTE +IBUS_IS_ATTRIBUTE +IBUS_TYPE_ATTRIBUTE +ibus_attribute_get_type +IBUS_ATTRIBUTE_CLASS +IBUS_IS_ATTRIBUTE_CLASS +IBUS_ATTRIBUTE_GET_CLASS +
+ +
+ibuspanelservice +IBusPanelService +IBusPanelService +IBusPanelServiceClass +ibus_panel_service_new +ibus_panel_service_candidate_clicked +ibus_panel_service_cursor_down +ibus_panel_service_cursor_up +ibus_panel_service_page_down +ibus_panel_service_page_up +ibus_panel_service_property_active +ibus_panel_service_property_show +ibus_panel_service_property_hide + +IBUS_PANEL_SERVICE +IBUS_IS_PANEL_SERVICE +IBUS_TYPE_PANEL_SERVICE +ibus_panel_service_get_type +IBUS_PANEL_SERVICE_CLASS +IBUS_IS_PANEL_SERVICE_CLASS +IBUS_PANEL_SERVICE_GET_CLASS
@@ -123,16 +172,14 @@ IBUS_COMPONENT_GET_CLASS IBusService IBusService IBusServiceClass -ServiceIBusMessageFunc -ServiceIBusSignalFunc +IBusServicePrivate ibus_service_new -ibus_service_get_path -ibus_service_handle_message -ibus_service_add_to_connection -ibus_service_get_connections -ibus_service_remove_from_connection -ibus_service_remove_from_all_connections -ibus_service_send_signal +ibus_service_get_object_path +ibus_service_get_connection +ibus_service_register +ibus_service_unregister +ibus_service_emit_signal +ibus_service_class_add_interfaces IBUS_SERVICE IBUS_IS_SERVICE @@ -190,6 +237,7 @@ ibus_serializable_get_attachment ibus_serializable_remove_attachment IBusSerializable IBusSerializableClass +IBusSerializablePrivate IBusSerializableSerializeFunc IBusSerializableDeserializeFunc IBusSerializableCopyFunc @@ -211,45 +259,6 @@ IBUS_SERIALIZABLE_GET_CLASS
-ibusconnection -IBusConnection -IBusConnection -IBusConnectionClass -IBusIBusMessageFunc -IBusIBusSignalFunc -IBusMessageFunc -ibus_connection_new -ibus_connection_set_connection -ibus_connection_open -ibus_connection_open_private -ibus_connection_close -ibus_connection_is_connected -ibus_connection_is_authenticated -ibus_connection_get_connection -ibus_connection_get_unix_user -ibus_connection_read_write_dispatch -ibus_connection_send -ibus_connection_send_signal -ibus_connection_send_signal_valist -ibus_connection_send_valist -ibus_connection_send_with_reply -ibus_connection_send_with_reply_and_block -ibus_connection_call -ibus_connection_call_with_reply -ibus_connection_flush -ibus_connection_register_object_path -ibus_connection_unregister_object_path - -IBUS_CONNECTION -IBUS_IS_CONNECTION -IBUS_TYPE_CONNECTION -ibus_connection_get_type -IBUS_CONNECTION_CLASS -IBUS_IS_CONNECTION_CLASS -IBUS_CONNECTION_GET_CLASS -
- -
ibuslookuptable IBusLookupTable IBusLookupTable @@ -393,6 +402,7 @@ IBUS_PANEL_SERVICE_GET_CLASS IBusFactory IBusFactory IBusFactoryClass +IBusFactoryPrivate ibus_factory_new ibus_factory_add_engine @@ -438,7 +448,9 @@ IBUS_PROPERTY_GET_CLASS IBusEngine IBusEngine IBusEngineClass +IBusEnginePrivate ibus_engine_new +ibus_engine_new_type ibus_engine_commit_text ibus_engine_update_preedit_text ibus_engine_update_preedit_text_with_mode @@ -538,6 +550,51 @@ IBUS_SERVER_GET_CLASS
+ibustext +IBusText +IBusText +IBusTextClass +ibus_text_new_from_string +ibus_text_new_from_ucs4 +ibus_text_new_from_static_string +ibus_text_new_from_printf +ibus_text_new_from_unichar +ibus_text_append_attribute +ibus_text_get_length + +IBUS_TEXT +IBUS_IS_TEXT +IBUS_TYPE_TEXT +ibus_text_get_type +IBUS_TEXT_CLASS +IBUS_IS_TEXT_CLASS +IBUS_TEXT_GET_CLASS +
+ +
+ibusserver +IBusServer +IBusServer +IBusServerClass +IBusNewConnectionFunc +ibus_server_new +ibus_server_listen +ibus_server_disconnect +ibus_server_get_address +ibus_server_get_id +ibus_server_is_connected +ibus_server_set_auth_mechanisms + +IBUS_SERVER +IBUS_IS_SERVER +IBUS_TYPE_SERVER +ibus_server_get_type +IBUS_SERVER_CLASS +IBUS_IS_SERVER_CLASS +IBUS_SERVER_GET_CLASS +
+ +
ibusconfigservice IBusConfigService IBusConfigService @@ -559,19 +616,11 @@ IBUS_CONFIG_SERVICE_GET_CLASS IBusProxy IBusProxy IBusProxyClass -ibus_proxy_new -ibus_proxy_send -ibus_proxy_call -ibus_proxy_call_with_reply -ibus_proxy_call_with_reply_and_block -ibus_proxy_send_with_reply -ibus_proxy_send_with_reply_and_block -ibus_proxy_handle_signal -ibus_proxy_get_name -ibus_proxy_get_unique_name -ibus_proxy_get_path -ibus_proxy_get_interface -ibus_proxy_get_connection +IBUS_PROXY_FLAGS +IBUS_PROXY_SET_FLAGS +IBUS_PROXY_UNSET_FLAGS +IBUS_PROXY_DESTROYED +ibus_proxy_destroy IBUS_PROXY IBUS_IS_PROXY @@ -2590,15 +2639,6 @@ IBUS_braille_dots_12345678
-ibusmainloop -DBusConnectionSetupFunc -DBusServerSetupFunc -ibus_mainloop_setup -ibus_dbus_server_setup -ibus_dbus_connection_setup -
- -
ibusdbus DBusError DBusMessage @@ -2609,34 +2649,6 @@ DBusConnection
-ibuspendingcall -IBusPendingCall -IBusPendingCallNotifyFunction -ibus_pending_call_ref -ibus_pending_call_unref -ibus_pending_call_set_notify -ibus_pending_call_cancel -ibus_pending_call_get_completed -ibus_pending_call_steal_reply -ibus_pending_call_block -ibus_pending_call_wait -ibus_pending_call_allocate_data_slot -ibus_pending_call_free_data_slot -ibus_pending_call_set_data -ibus_pending_call_get_data -
- -
-ibuserror -IBusError -ibus_error_new -ibus_error_new_from_text -ibus_error_new_from_printf -ibus_error_new_from_message -ibus_error_free -
- -
ibusshare IBUS_SERVICE_IBUS IBUS_SERVICE_PANEL @@ -2689,68 +2701,3 @@ IBUS_MINOR_VERSION IBUS_MICRO_VERSION IBUS_CHECK_VERSION
- -
-ibusmessage -IBUS_TYPE_OBJECT_PATH -IBUS_TYPE_ARRAY -IBUS_TYPE_STRUCT -IBUS_TYPE_DICT_ENTRY -IBUS_TYPE_VARIANT -IBusMessage -IBusMessageIter -ibus_type_get_object_path -ibus_type_get_array -ibus_type_get_struct -ibus_type_get_dict_entry -ibus_type_get_variant -ibus_message_new -ibus_message_ref -ibus_message_unref -ibus_message_new_method_call -ibus_message_new_method_return -ibus_message_new_error -ibus_message_new_error_printf -ibus_message_new_signal -ibus_message_is_method_call -ibus_message_is_error -ibus_message_is_signal -ibus_message_set_destination -ibus_message_set_sender -ibus_message_set_error_name -ibus_message_set_interface -ibus_message_set_member -ibus_message_set_path -ibus_message_set_no_reply -ibus_message_set_reply_serial -ibus_message_get_type -ibus_message_get_destination -ibus_message_get_sender -ibus_message_get_error_name -ibus_message_get_error_message -ibus_message_get_interface -ibus_message_get_member -ibus_message_get_path -ibus_message_get_no_reply -ibus_message_get_reply_serial -ibus_message_get_serial -ibus_message_append_args -ibus_message_append_args_valist -ibus_message_get_args -ibus_message_get_args_valist -ibus_message_iter_init_append -ibus_message_iter_append -ibus_message_iter_copy_data -ibus_message_iter_init -ibus_message_iter_get_basic -ibus_message_iter_get -ibus_message_iter_next -ibus_message_iter_has_next -ibus_message_iter_open_container -ibus_message_iter_close_container -ibus_message_iter_recurse -ibus_message_iter_get_arg_type -ibus_message_iter_get_element_type -ibus_message_to_string -
- diff --git a/docs/reference/ibus/ibus.types b/docs/reference/ibus/ibus.types index f992c65..016e9ce 100644 --- a/docs/reference/ibus/ibus.types +++ b/docs/reference/ibus/ibus.types @@ -1,4 +1,3 @@ -ibus_connection_get_type ibus_hotkey_profile_get_type ibus_object_get_type ibus_config_get_type @@ -12,11 +11,9 @@ ibus_prop_state_get_type ibus_modifier_type_get_type ibus_capabilite_get_type ibus_orientation_get_type -ibus_service_get_type ibus_factory_get_type ibus_text_get_type ibus_config_service_get_type -ibus_server_get_type ibus_attribute_get_type ibus_attr_list_get_type ibus_engine_desc_get_type diff --git a/gconf/Makefile.am b/gconf/Makefile.am index 70bcf34..0770051 100644 --- a/gconf/Makefile.am +++ b/gconf/Makefile.am @@ -20,7 +20,7 @@ # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA -libibus = $(top_builddir)/src/libibus.la +libibus = $(top_builddir)/src/libibus-2.0.la libexec_PROGRAMS = \ ibus-gconf \ @@ -33,8 +33,8 @@ ibus_gconf_SOURCES = \ $(NULL) ibus_gconf_CFLAGS = \ @GLIB2_CFLAGS@ \ + @GIO2_CFLAGS@ \ @GCONF_CFLAGS@ \ - @DBUS_CFLAGS@ \ -DG_LOG_DOMAIN=\"IBUS\" \ -I$(top_srcdir)/src \ -I$(top_builddir)/src \ @@ -42,8 +42,8 @@ ibus_gconf_CFLAGS = \ ibus_gconf_LDADD = \ @GOBJECT2_LIBS@ \ @GLIB2_LIBS@ \ + @GIO2_LIBS@ \ @GCONF_LIBS@ \ - @DBUS_LIBS@ \ $(libibus) \ $(NULL) ibus_gconf_DEPENDENCIES = \ diff --git a/gconf/config.c b/gconf/config.c index 474e111..0abd7ce 100644 --- a/gconf/config.c +++ b/gconf/config.c @@ -2,62 +2,58 @@ /* vim:set et sts=4: */ #include -#include #include #include "config.h" #define GCONF_PREFIX "/desktop/ibus" /* functions prototype */ -static void ibus_config_gconf_class_init (IBusConfigGConfClass *klass); -static void ibus_config_gconf_init (IBusConfigGConf *config); -static void ibus_config_gconf_destroy (IBusConfigGConf *config); +static void ibus_config_gconf_class_init (IBusConfigGConfClass *klass); +static void ibus_config_gconf_init (IBusConfigGConf *config); +static void ibus_config_gconf_destroy (IBusConfigGConf *config); static gboolean ibus_config_gconf_set_value (IBusConfigService *config, const gchar *section, const gchar *name, - const GValue *value, - IBusError **error); -static gboolean ibus_config_gconf_get_value (IBusConfigService *config, + GVariant *value, + GError **error); +static GVariant *ibus_config_gconf_get_value (IBusConfigService *config, const gchar *section, const gchar *name, - GValue *value, - IBusError **error); -static gboolean ibus_config_gconf_unset (IBusConfigService *config, - const gchar *section, - const gchar *name, - IBusError **error); - -static GConfValue *_to_gconf_value (const GValue *value); -static void _from_gconf_value (GValue *value, - const GConfValue *gvalue); + GError **error); +static gboolean ibus_config_gconf_unset_value (IBusConfigService *config, + const gchar *section, + const gchar *name, + GError **error); +static GConfValue *_to_gconf_value (GVariant *value); +static GVariant *_from_gconf_value (const GConfValue *gvalue); static IBusConfigServiceClass *parent_class = NULL; GType ibus_config_gconf_get_type (void) { - static GType type = 0; - - static const GTypeInfo type_info = { - sizeof (IBusConfigGConfClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) ibus_config_gconf_class_init, - NULL, - NULL, - sizeof (IBusConfigGConf), - 0, - (GInstanceInitFunc) ibus_config_gconf_init, - }; - - if (type == 0) { - type = g_type_register_static (IBUS_TYPE_CONFIG_SERVICE, - "IBusConfigGConf", - &type_info, - (GTypeFlags) 0); - } - - return type; + static GType type = 0; + + static const GTypeInfo type_info = { + sizeof (IBusConfigGConfClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) ibus_config_gconf_class_init, + NULL, + NULL, + sizeof (IBusConfigGConf), + 0, + (GInstanceInitFunc) ibus_config_gconf_init, + }; + + if (type == 0) { + type = g_type_register_static (IBUS_TYPE_CONFIG_SERVICE, + "IBusConfigGConf", + &type_info, + (GTypeFlags) 0); + } + + return type; } static void @@ -67,10 +63,10 @@ ibus_config_gconf_class_init (IBusConfigGConfClass *klass) parent_class = (IBusConfigServiceClass *) g_type_class_peek_parent (klass); - IBUS_OBJECT_CLASS (object_class)->destroy = (IBusObjectDestroyFunc) ibus_config_gconf_destroy; - IBUS_CONFIG_SERVICE_CLASS (object_class)->set_value = ibus_config_gconf_set_value; - IBUS_CONFIG_SERVICE_CLASS (object_class)->get_value = ibus_config_gconf_get_value; - IBUS_CONFIG_SERVICE_CLASS (object_class)->unset = ibus_config_gconf_unset; + IBUS_OBJECT_CLASS (object_class)->destroy = (IBusObjectDestroyFunc) ibus_config_gconf_destroy; + IBUS_CONFIG_SERVICE_CLASS (object_class)->set_value = ibus_config_gconf_set_value; + IBUS_CONFIG_SERVICE_CLASS (object_class)->get_value = ibus_config_gconf_get_value; + IBUS_CONFIG_SERVICE_CLASS (object_class)->unset_value = ibus_config_gconf_unset_value; } static void @@ -80,7 +76,6 @@ _value_changed_cb (GConfClient *client, IBusConfigGConf *config) { gchar *p, *section, *name; - GValue v = { 0 }; g_return_if_fail (key != NULL); g_return_if_fail (value != NULL); @@ -91,13 +86,14 @@ _value_changed_cb (GConfClient *client, *(name - 1) = '\0'; - _from_gconf_value (&v, value); + GVariant *variant = _from_gconf_value (value); + g_return_if_fail (variant != NULL); ibus_config_service_value_changed ((IBusConfigService *) config, section, name, - &v); + variant); + g_variant_unref (variant); g_free (p); - g_value_unset (&v); } static void @@ -120,140 +116,132 @@ ibus_config_gconf_destroy (IBusConfigGConf *config) config->client = NULL; } - IBUS_OBJECT_CLASS (parent_class)->destroy ((IBusObject *)config); + IBUS_OBJECT_CLASS (parent_class)->destroy ((IBusObject *)config); } static GConfValue * -_to_gconf_value (const GValue *value) +_to_gconf_value (GVariant *value) { - GConfValue *gv; - GType type = G_VALUE_TYPE (value); + GConfValue *gv = NULL; - switch (type) { - case G_TYPE_STRING: + switch (g_variant_classify (value)) { + case G_VARIANT_CLASS_STRING: { gv = gconf_value_new (GCONF_VALUE_STRING); - gconf_value_set_string (gv, g_value_get_string (value)); - } - break; - case G_TYPE_INT: - { - gv = gconf_value_new (GCONF_VALUE_INT); - gconf_value_set_int (gv, g_value_get_int (value)); + gconf_value_set_string (gv, g_variant_get_string (value, NULL)); } break; - case G_TYPE_UINT: + case G_VARIANT_CLASS_INT32: { gv = gconf_value_new (GCONF_VALUE_INT); - gconf_value_set_int (gv, g_value_get_uint (value)); + gconf_value_set_int (gv, g_variant_get_int32 (value)); } break; - case G_TYPE_BOOLEAN: + case G_VARIANT_CLASS_BOOLEAN: { gv = gconf_value_new (GCONF_VALUE_BOOL); - gconf_value_set_bool (gv, g_value_get_boolean (value)); + gconf_value_set_bool (gv, g_variant_get_boolean (value)); } break; - case G_TYPE_DOUBLE: + case G_VARIANT_CLASS_DOUBLE: { gv = gconf_value_new (GCONF_VALUE_FLOAT); - gconf_value_set_float (gv, g_value_get_double (value)); + gconf_value_set_float (gv, g_variant_get_double (value)); } break; - case G_TYPE_FLOAT: + case G_VARIANT_CLASS_ARRAY: { - gv = gconf_value_new (GCONF_VALUE_FLOAT); - gconf_value_set_float (gv, g_value_get_float (value)); - } - break; - default: - if (type == G_TYPE_VALUE_ARRAY) { - - GSList *l = NULL; - GType list_type = G_TYPE_STRING; - GValueArray *array = g_value_get_boxed (value); - gint i; - - if (array && array->n_values > 0) { - list_type = G_VALUE_TYPE (&(array->values[0])); - } + const GVariantType *element_type = g_variant_type_element (g_variant_get_type (value)); + + GConfValueType type = GCONF_VALUE_INVALID; + if (g_variant_type_equal (element_type, G_VARIANT_TYPE_STRING)) + type = GCONF_VALUE_STRING; + else if (g_variant_type_equal (element_type, G_VARIANT_TYPE_INT32)) + type = GCONF_VALUE_INT; + else if (g_variant_type_equal (element_type, G_VARIANT_TYPE_BOOLEAN)) + type = GCONF_VALUE_BOOL; + else if (g_variant_type_equal (element_type, G_VARIANT_TYPE_DOUBLE)) + type = GCONF_VALUE_FLOAT; + else + g_return_val_if_reached (NULL); gv = gconf_value_new (GCONF_VALUE_LIST); - - switch (list_type) { - case G_TYPE_STRING: - gconf_value_set_list_type (gv, GCONF_VALUE_STRING); break; - case G_TYPE_INT: - case G_TYPE_UINT: - gconf_value_set_list_type (gv, GCONF_VALUE_INT); break; - case G_TYPE_BOOLEAN: - gconf_value_set_list_type (gv, GCONF_VALUE_BOOL); break; - case G_TYPE_FLOAT: - case G_TYPE_DOUBLE: - gconf_value_set_list_type (gv, GCONF_VALUE_FLOAT); break; - default: - g_assert_not_reached (); + gconf_value_set_list_type (gv, type); + + GSList *elements = NULL; + GVariantIter iter; + GVariant *child; + g_variant_iter_init (&iter, value); + while ((child = g_variant_iter_next_value (&iter)) != NULL) { + elements = g_slist_append (elements, _to_gconf_value (child)); + g_variant_unref (child); } - - for (i = 0; array && i < array->n_values; i++) { - GConfValue *tmp; - g_assert (G_VALUE_TYPE (&(array->values[i])) == list_type); - tmp = _to_gconf_value (&(array->values[i])); - l = g_slist_append (l, tmp); - } - gconf_value_set_list_nocopy (gv, l); + gconf_value_set_list_nocopy (gv, elements); } - else - g_assert_not_reached (); + break; + default: + g_return_val_if_reached (NULL); } + return gv; } -static void -_from_gconf_value (GValue *value, - const GConfValue *gv) +static GVariant * +_from_gconf_value (const GConfValue *gv) { - g_assert (value); - g_assert (gv); + g_assert (gv != NULL); switch (gv->type) { case GCONF_VALUE_STRING: - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, gconf_value_get_string (gv)); - return; + return g_variant_new_string (gconf_value_get_string (gv)); case GCONF_VALUE_INT: - g_value_init (value, G_TYPE_INT); - g_value_set_int (value, gconf_value_get_int (gv)); - return; + return g_variant_new_int32 (gconf_value_get_int (gv)); case GCONF_VALUE_FLOAT: - g_value_init (value, G_TYPE_DOUBLE); - g_value_set_double (value, gconf_value_get_float (gv)); - return; + return g_variant_new_double (gconf_value_get_float (gv)); case GCONF_VALUE_BOOL: - g_value_init (value, G_TYPE_BOOLEAN); - g_value_set_boolean (value, gconf_value_get_bool (gv)); - return; + return g_variant_new_boolean (gconf_value_get_bool (gv)); case GCONF_VALUE_LIST: { - g_value_init (value, G_TYPE_VALUE_ARRAY); - - GSList *list, *p; - GValueArray *va; - - list = gconf_value_get_list (gv); - va = g_value_array_new (g_slist_length (list)); - for (p = list; p != NULL; p = p->next) { - GValue tmp = {0}; - _from_gconf_value (&tmp, (GConfValue *) p->data); - g_value_array_append (va, &tmp); + GVariantBuilder builder; + switch (gconf_value_get_list_type (gv)) { + case GCONF_VALUE_STRING: + g_variant_builder_init (&builder, G_VARIANT_TYPE("as")); break; + case GCONF_VALUE_INT: + g_variant_builder_init (&builder, G_VARIANT_TYPE("ai")); break; + case GCONF_VALUE_FLOAT: + g_variant_builder_init (&builder, G_VARIANT_TYPE("ad")); break; + case GCONF_VALUE_BOOL: + g_variant_builder_init (&builder, G_VARIANT_TYPE("ab")); break; + break; + default: + g_assert_not_reached (); } - g_value_take_boxed (value, va); + GSList *list = gconf_value_get_list (gv); + GSList *p = list; + while (p != NULL) { + switch (gconf_value_get_list_type (gv)) { + case GCONF_VALUE_STRING: + g_variant_builder_add (&builder, "s", gconf_value_get_string ((GConfValue *)p->data)); + break; + case GCONF_VALUE_INT: + g_variant_builder_add (&builder, "i", gconf_value_get_int ((GConfValue *)p->data)); + break; + case GCONF_VALUE_FLOAT: + g_variant_builder_add (&builder, "d", gconf_value_get_float ((GConfValue *)p->data)); + break; + case GCONF_VALUE_BOOL: + g_variant_builder_add (&builder, "b", gconf_value_get_bool ((GConfValue *)p->data)); + break; + default: + g_assert_not_reached (); + } + p = p->next; + } + return g_variant_builder_end (&builder); } - return; default: g_assert_not_reached (); - break; } } @@ -262,88 +250,86 @@ static gboolean ibus_config_gconf_set_value (IBusConfigService *config, const gchar *section, const gchar *name, - const GValue *value, - IBusError **error) + GVariant *value, + GError **error) { + g_debug ("set value: %s : %s", section, name); gchar *key; GConfValue *gv; - GError *gerror = NULL; gv = _to_gconf_value (value); - + if (gv == NULL) { + gchar *str = g_variant_print (value, TRUE); + *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Can not set config value [%s:%s] to %s.", + section, name, str); + g_free (str); + return FALSE; + } key = g_strdup_printf (GCONF_PREFIX"/%s/%s", section, name); + gconf_client_set (((IBusConfigGConf *)config)->client, key, gv, error); - gconf_client_set (((IBusConfigGConf *)config)->client, key, gv, &gerror); g_free (key); gconf_value_free (gv); - if (gerror != NULL) { - if (error) { - *error = ibus_error_new_from_text (DBUS_ERROR_FAILED, gerror->message); - g_error_free (gerror); - } + if (*error != NULL) { return FALSE; } - return TRUE; } -static gboolean + +static GVariant * ibus_config_gconf_get_value (IBusConfigService *config, const gchar *section, const gchar *name, - GValue *value, - IBusError **error) + GError **error) { - gchar *key; - GConfValue *gv; - key = g_strdup_printf (GCONF_PREFIX"/%s/%s", section, name); + gchar *key = g_strdup_printf (GCONF_PREFIX"/%s/%s", section, name); + + GConfValue *gv = gconf_client_get (((IBusConfigGConf *) config)->client, key, NULL); - 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; + *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Config value [%s:%s] does not exist.", section, name); + return NULL; } - _from_gconf_value (value, gv); + GVariant *variant = _from_gconf_value (gv); gconf_value_free (gv); - return TRUE; +#if 0 + gchar *str = g_variant_print (variant, TRUE); + g_debug ("get value: [%s:%s] = %s", section, name, str); + g_free (str); +#endif + return variant; } + static gboolean -ibus_config_gconf_unset (IBusConfigService *config, - const gchar *section, - const gchar *name, - IBusError **error) +ibus_config_gconf_unset_value (IBusConfigService *config, + const gchar *section, + const gchar *name, + GError **error) { - gchar *key; - GError *gerror = NULL; - - key = g_strdup_printf (GCONF_PREFIX"/%s/%s", section, name); + gchar *key = g_strdup_printf (GCONF_PREFIX"/%s/%s", section, name); - gconf_client_unset (((IBusConfigGConf *)config)->client, key, &gerror); + gconf_client_unset (((IBusConfigGConf *)config)->client, key, error); g_free (key); - if (gerror != NULL) { - if (error) { - *error = ibus_error_new_from_text (DBUS_ERROR_FAILED, gerror->message); - g_error_free (gerror); - } + if (*error != NULL) { return FALSE; } - return TRUE; } IBusConfigGConf * -ibus_config_gconf_new (IBusConnection *connection) +ibus_config_gconf_new (GDBusConnection *connection) { IBusConfigGConf *config; - config = (IBusConfigGConf *) g_object_new (IBUS_TYPE_CONFIG_GCONF, - "path", IBUS_PATH_CONFIG, + "object-path", IBUS_PATH_CONFIG, "connection", connection, NULL); return config; diff --git a/gconf/config.h b/gconf/config.h index d3700dc..9ce4097 100644 --- a/gconf/config.h +++ b/gconf/config.h @@ -13,17 +13,17 @@ typedef struct _IBusConfigGConf IBusConfigGConf; typedef struct _IBusConfigGConfClass IBusConfigGConfClass; struct _IBusConfigGConf { - IBusConfigService parent; + IBusConfigService parent; GConfClient *client; }; struct _IBusConfigGConfClass { - IBusConfigServiceClass parent; + IBusConfigServiceClass parent; }; GType ibus_config_gconf_get_type (void); -IBusConfigGConf *ibus_config_gconf_new (IBusConnection *connection); +IBusConfigGConf *ibus_config_gconf_new (GDBusConnection *connection); #endif diff --git a/gconf/main.c b/gconf/main.c index 1661013..57d7f6a 100644 --- a/gconf/main.c +++ b/gconf/main.c @@ -43,7 +43,7 @@ ibus_gconf_start (void) ibus_main (); } -int +gint main (gint argc, gchar **argv) { GError *error = NULL; diff --git a/ibus-1.0.pc.in b/ibus-2.0.pc.in similarity index 60% rename from ibus-1.0.pc.in rename to ibus-2.0.pc.in index 3595775..2af3cac 100644 --- a/ibus-1.0.pc.in +++ b/ibus-2.0.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: IBus Description: IBus Library Version: @VERSION@ -Requires: gobject-2.0 -Libs: -L${libdir} -libus -Cflags: -I${includedir}/ibus-1.0 +Requires: gobject-2.0 gio-2.0 +Libs: -L${libdir} -libus-2.0 +Cflags: -I${includedir}/ibus-2.0 diff --git a/ibus.spec.in b/ibus.spec.in index 778d524..7a625ff 100644 --- a/ibus.spec.in +++ b/ibus.spec.in @@ -134,7 +134,7 @@ make %{?_smp_mflags} %install rm -rf $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install -rm -f $RPM_BUILD_ROOT%{_libdir}/libibus.la +rm -f $RPM_BUILD_ROOT%{_libdir}/libibus-2.0.la rm -f $RPM_BUILD_ROOT%{_libdir}/gtk-2.0/%{gtk2_binary_version}/immodules/im-ibus.la rm -f $RPM_BUILD_ROOT%{_libdir}/gtk-3.0/%{gtk3_binary_version}/immodules/im-ibus.la @@ -144,8 +144,6 @@ install -pm 644 -D %{SOURCE1} $RPM_BUILD_ROOT%{_xinputconf} # install .desktop files echo "NoDisplay=true" >> $RPM_BUILD_ROOT%{_datadir}/applications/ibus.desktop echo "NoDisplay=true" >> $RPM_BUILD_ROOT%{_datadir}/applications/ibus-setup.desktop -echo "X-GNOME-Autostart-enabled=false" >> $RPM_BUILD_ROOT%{_sysconfdir}/xdg/autostart/ibus.desktop -rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/xdg/autostart/ibus.desktop desktop-file-install --delete-original \ --dir $RPM_BUILD_ROOT%{_datadir}/applications \ $RPM_BUILD_ROOT%{_datadir}/applications/* @@ -226,8 +224,8 @@ fi %files libs %defattr(-,root,root,-) -%{_libdir}/libibus.so.* -%{_libdir}/girepository-1.0/IBus-1.0.typelib +%{_libdir}/libibus-2.0.so.* +%{_libdir}/girepository-1.0/IBus-2.0.typelib %files gtk2 %defattr(-,root,root,-) @@ -242,8 +240,8 @@ fi %{_libdir}/lib*.so %{_libdir}/pkgconfig/* %{_includedir}/* -%{_datadir}/gir-1.0/IBus-1.0.gir -%{_datadir}/vala/vapi/ibus-1.0.vapi +%{_datadir}/gir-1.0/IBus-2.0.gir +%{_datadir}/vala/vapi/ibus-2.0.vapi %files devel-docs %defattr(-,root,root,-) diff --git a/ibus/common.py b/ibus/common.py index b2cdc3d..dfc6db6 100644 --- a/ibus/common.py +++ b/ibus/common.py @@ -98,7 +98,7 @@ import ctypes # return None # return address -libibus = ctypes.CDLL("libibus.so.2") +libibus = ctypes.CDLL("libibus-2.0.so.0") get_address = libibus.ibus_get_address get_address.restype=ctypes.c_char_p diff --git a/m4/introspection.m4 b/m4/introspection.m4 new file mode 100644 index 0000000..589721c --- /dev/null +++ b/m4/introspection.m4 @@ -0,0 +1,94 @@ +dnl -*- mode: autoconf -*- +dnl Copyright 2009 Johan Dahlin +dnl +dnl This file is free software; the author(s) gives unlimited +dnl permission to copy and/or distribute it, with or without +dnl modifications, as long as this notice is preserved. +dnl + +# serial 1 + +m4_define([_GOBJECT_INTROSPECTION_CHECK_INTERNAL], +[ + AC_BEFORE([AC_PROG_LIBTOOL],[$0])dnl setup libtool first + AC_BEFORE([AM_PROG_LIBTOOL],[$0])dnl setup libtool first + AC_BEFORE([LT_INIT],[$0])dnl setup libtool first + + dnl enable/disable introspection + m4_if([$2], [require], + [dnl + enable_introspection=yes + ],[dnl + AC_ARG_ENABLE(introspection, + AS_HELP_STRING([--enable-introspection[=@<:@no/auto/yes@:>@]], + [Enable introspection for this build]),, + [enable_introspection=auto]) + ])dnl + + AC_MSG_CHECKING([for gobject-introspection]) + + dnl presence/version checking + AS_CASE([$enable_introspection], + [no], [dnl + found_introspection="no (disabled, use --enable-introspection to enable)" + ],dnl + [yes],[dnl + PKG_CHECK_EXISTS([gobject-introspection-1.0],, + AC_MSG_ERROR([gobject-introspection-1.0 is not installed])) + PKG_CHECK_EXISTS([gobject-introspection-1.0 >= $1], + found_introspection=yes, + AC_MSG_ERROR([You need to have gobject-introspection >= $1 installed to build AC_PACKAGE_NAME])) + ],dnl + [auto],[dnl + PKG_CHECK_EXISTS([gobject-introspection-1.0 >= $1], found_introspection=yes, found_introspection=no) + ],dnl + [dnl + AC_MSG_ERROR([invalid argument passed to --enable-introspection, should be one of @<:@no/auto/yes@:>@]) + ])dnl + + AC_MSG_RESULT([$found_introspection]) + + INTROSPECTION_SCANNER= + INTROSPECTION_COMPILER= + INTROSPECTION_GENERATE= + INTROSPECTION_GIRDIR= + INTROSPECTION_TYPELIBDIR= + if test "x$found_introspection" = "xyes"; then + INTROSPECTION_SCANNER=`$PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0` + INTROSPECTION_COMPILER=`$PKG_CONFIG --variable=g_ir_compiler gobject-introspection-1.0` + INTROSPECTION_GENERATE=`$PKG_CONFIG --variable=g_ir_generate gobject-introspection-1.0` + INTROSPECTION_GIRDIR=`$PKG_CONFIG --variable=girdir gobject-introspection-1.0` + INTROSPECTION_TYPELIBDIR="$($PKG_CONFIG --variable=typelibdir gobject-introspection-1.0)" + INTROSPECTION_CFLAGS=`$PKG_CONFIG --cflags gobject-introspection-1.0` + INTROSPECTION_LIBS=`$PKG_CONFIG --libs gobject-introspection-1.0` + INTROSPECTION_MAKEFILE=`$PKG_CONFIG --variable=datadir gobject-introspection-1.0`/gobject-introspection-1.0/Makefile.introspection + fi + AC_SUBST(INTROSPECTION_SCANNER) + AC_SUBST(INTROSPECTION_COMPILER) + AC_SUBST(INTROSPECTION_GENERATE) + AC_SUBST(INTROSPECTION_GIRDIR) + AC_SUBST(INTROSPECTION_TYPELIBDIR) + AC_SUBST(INTROSPECTION_CFLAGS) + AC_SUBST(INTROSPECTION_LIBS) + AC_SUBST(INTROSPECTION_MAKEFILE) + + AM_CONDITIONAL(HAVE_INTROSPECTION, test "x$found_introspection" = "xyes") +]) + + +dnl Usage: +dnl GOBJECT_INTROSPECTION_CHECK([minimum-g-i-version]) + +AC_DEFUN([GOBJECT_INTROSPECTION_CHECK], +[ + _GOBJECT_INTROSPECTION_CHECK_INTERNAL([$1]) +]) + +dnl Usage: +dnl GOBJECT_INTROSPECTION_REQUIRE([minimum-g-i-version]) + + +AC_DEFUN([GOBJECT_INTROSPECTION_REQUIRE], +[ + _GOBJECT_INTROSPECTION_CHECK_INTERNAL([$1], [require]) +]) diff --git a/memconf/main.cc b/memconf/main.cc index b2c6c83..a4d29ea 100644 --- a/memconf/main.cc +++ b/memconf/main.cc @@ -42,7 +42,7 @@ ibus_gconf_start (void) ibus_main (); } -int +gint main (gint argc, gchar **argv) { GError *error = NULL; diff --git a/po/POTFILES.in b/po/POTFILES.in index cfa9c7c..3378566 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,12 +1,10 @@ src/ibusbus.c src/ibusconfig.c -src/ibusconnection.c src/ibusengine.c src/ibushotkey.c src/ibusinputcontext.c src/ibusobject.c src/ibusproxy.c -src/ibusserver.c src/ibusservice.c src/keyname-table.h bus/ibus.desktop.in diff --git a/po/ar.po b/po/ar.po index 84c99d1..573b306 100644 --- a/po/ar.po +++ b/po/ar.po @@ -8,10 +8,11 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2009-04-06 11:45+0800\n" "Last-Translator: Muayyad Alsadi \n" "Language-Team: Arabic \n" +"Language: ar\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -90,21 +91,21 @@ msgstr "نظام IBus هو ناقل إدخال ذكي لنظام لينكس وي msgid "translator-credits" msgstr "Muayyad Alsadi " -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 #, fuzzy msgid "About the input method" msgstr "طرق الإدخال" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "تبديل طريقة الإدخال" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "حول" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 #, fuzzy msgid "About the Input Method" msgstr "طرق الإدخال" diff --git a/po/as.po b/po/as.po index 615b411..0640b66 100644 --- a/po/as.po +++ b/po/as.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master.ibus.as\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-05-05 16:04+0530\n" "Last-Translator: Amitakhya Phukan \n" "Language-Team: Assamese \n" +"Language: as\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -91,20 +92,20 @@ msgstr "IBus এটা Linux/Unix ৰ কাৰণে বুদ্ধিমা msgid "translator-credits" msgstr "অমিতাক্ষ ফুকন (aphukan@fedoraproject.org)" -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 msgid "About the input method" msgstr "নিবেশ পদ্ধতিৰ বিষয়ে" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "নিবেশ পদ্ধতি সলনি কৰক" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "বিষয়ে" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 msgid "About the Input Method" msgstr "নিবেশ পদ্ধতিৰ বিষয়ে" diff --git a/po/bn_IN.po b/po/bn_IN.po index 3e9579b..c18f5fa 100644 --- a/po/bn_IN.po +++ b/po/bn_IN.po @@ -8,10 +8,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-08-02 08:23+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-08-02 18:27+0530\n" "Last-Translator: Runa Bhattacharjee \n" "Language-Team: Bengali INDIA \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -232,7 +233,9 @@ msgstr "ডিফল্ট অবস্থায় ইনপুট পদ্ধত #: ../data/ibus.schemas.in.h:7 msgid "Enable input method by default when the application gets input focus" -msgstr "ইনপুট প্রাপ্ত করার উদ্দেশ্যে অ্যাপ্লিকেশনে ফোকাস করা হলে, ডিফল্ট রূপে ইনপুট পদ্ধতি সক্রিয় করা হবে" +msgstr "" +"ইনপুট প্রাপ্ত করার উদ্দেশ্যে অ্যাপ্লিকেশনে ফোকাস করা হলে, ডিফল্ট রূপে ইনপুট পদ্ধতি " +"সক্রিয় করা হবে" #: ../data/ibus.schemas.in.h:8 msgid "Language panel position" @@ -506,4 +509,3 @@ msgstr "উল্লম্ব" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "সক্রিয় অবস্থায়" - diff --git a/po/ca.po b/po/ca.po index 927d790..f05ee7e 100644 --- a/po/ca.po +++ b/po/ca.po @@ -20,10 +20,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2009-09-19 20:43+0200\n" "Last-Translator: Patricia Rivera Escuder \n" "Language-Team: Catalan \n" +"Language: ca\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -105,21 +106,21 @@ msgstr "" "Patricia Rivera Escuder , 2009\n" "Xavier Conde Rueda " -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 #, fuzzy msgid "About the input method" msgstr "Quant al mètode d'entrada" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "Canvia el mètode d'entrada" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "Quant a" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 msgid "About the Input Method" msgstr "Quant al mètode d'entrada" diff --git a/po/da.po b/po/da.po index bdf4e93..5a0a4b7 100644 --- a/po/da.po +++ b/po/da.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2009-06-11 17:58+0200\n" "Last-Translator: Kris Thomsen \n" "Language-Team: Danish \n" +"Language: da\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -93,21 +94,21 @@ msgstr "" "Dansk-gruppen \n" "Mere info: http://www.dansk-gruppen.dk" -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 #, fuzzy msgid "About the input method" msgstr "Inddatametoder" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "Skift inddatametode" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "Om" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 #, fuzzy msgid "About the Input Method" msgstr "Inddatametoder" diff --git a/po/de.po b/po/de.po index 5ac1292..d490ff0 100644 --- a/po/de.po +++ b/po/de.po @@ -10,10 +10,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master.de\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-28 18:37+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-29 22:37+1000\n" "Last-Translator: \n" "Language-Team: \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -236,7 +237,9 @@ msgstr "Eingabemethode standardmäßig aktivieren" #: ../data/ibus.schemas.in.h:7 msgid "Enable input method by default when the application gets input focus" -msgstr "Eingabemethode standardmäßig aktivieren, wenn die Anwendung Eingabefokus erlangt" +msgstr "" +"Eingabemethode standardmäßig aktivieren, wenn die Anwendung Eingabefokus " +"erlangt" #: ../data/ibus.schemas.in.h:8 msgid "Language panel position" @@ -300,7 +303,8 @@ msgstr "" #: ../data/ibus.schemas.in.h:21 msgid "The shortcut keys for switching to the next input method in the list" -msgstr "Tastenkombination zum Wechseln zur nächsten Eingabemethode in der Liste" +msgstr "" +"Tastenkombination zum Wechseln zur nächsten Eingabemethode in der Liste" #: ../data/ibus.schemas.in.h:22 msgid "The shortcut keys for switching to the previous input method" @@ -463,11 +467,13 @@ msgstr "Vorherige Eingabemethode:" #: ../setup/setup.ui.h:37 msgid "Remove the selected input method from the enabled input methods" -msgstr "Entfernen Sie die gewählte Eingabemethode aus den aktivierten Eingabemethoden" +msgstr "" +"Entfernen Sie die gewählte Eingabemethode aus den aktivierten Eingabemethoden" #: ../setup/setup.ui.h:38 msgid "Set the behavior of ibus how to show or hide language bar" -msgstr "Verhalten von IBus einstellen, das Sprach-Panel anzuzeigen oder zu verstecken" +msgstr "" +"Verhalten von IBus einstellen, das Sprach-Panel anzuzeigen oder zu verstecken" #: ../setup/setup.ui.h:39 msgid "Set the orientation of candidates in lookup table" @@ -493,11 +499,13 @@ msgstr "Starte IBus bei der Anmeldung" #: ../setup/setup.ui.h:47 msgid "The shortcut keys for switching to next input method in the list" -msgstr "Tastenkombination zum Wechseln zur nächsten Eingabemethode in der Liste" +msgstr "" +"Tastenkombination zum Wechseln zur nächsten Eingabemethode in der Liste" #: ../setup/setup.ui.h:48 msgid "The shortcut keys for switching to previous input method in the list" -msgstr "Tastenkombination zum Wechseln zur vorherigen Eingabemethode in der Liste" +msgstr "" +"Tastenkombination zum Wechseln zur vorherigen Eingabemethode in der Liste" #: ../setup/setup.ui.h:50 msgid "Top left corner" @@ -518,4 +526,3 @@ msgstr "Vertikal" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "Wenn aktiv" - diff --git a/po/es.po b/po/es.po index 3239516..2fb47a4 100644 --- a/po/es.po +++ b/po/es.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-30 16:35+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: \n" "Last-Translator: Héctor Daniel Cabrera \n" "Language-Team: Fedora Spanish \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -50,8 +51,12 @@ msgid "Next page" msgstr "Siguiente página" #: ../ui/gtk/main.py:57 -msgid "Some input methods have been installed, removed or updated. Please restart ibus input platform." -msgstr "Algunos métodos de entrada han sido instalados, eliminados o actualizados. Por favor, reinicie la plataforma de entrada ibus." +msgid "" +"Some input methods have been installed, removed or updated. Please restart " +"ibus input platform." +msgstr "" +"Algunos métodos de entrada han sido instalados, eliminados o actualizados. " +"Por favor, reinicie la plataforma de entrada ibus." #: ../ui/gtk/main.py:62 msgid "Restart Now" @@ -85,45 +90,39 @@ msgstr "IBus es un bus de entrada inteligente para Linux/Unix." msgid "translator-credits" msgstr "Domingo Becker, , 2009" -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 msgid "About the input method" msgstr "Acerca del método de entrada" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "Cambiar método de entrada" -#: ../ui/gtk/languagebar.py:358 -#: ../ui/gtk/engineabout.py:35 -#: ../setup/engineabout.py:35 -#: ../setup/setup.ui.h:16 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 +#: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "Acerca de" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 msgid "About the Input Method" msgstr "Acerca del Método de Entrada" -#: ../ui/gtk/engineabout.py:63 -#: ../setup/engineabout.py:63 +#: ../ui/gtk/engineabout.py:63 ../setup/engineabout.py:63 #, python-format msgid "Language: %s\n" msgstr "Idioma: %s\n" -#: ../ui/gtk/engineabout.py:65 -#: ../setup/engineabout.py:65 +#: ../ui/gtk/engineabout.py:65 ../setup/engineabout.py:65 #, python-format msgid "Keyboard layout: %s\n" msgstr "Diseño del teclado: %s\n" -#: ../ui/gtk/engineabout.py:67 -#: ../setup/engineabout.py:67 +#: ../ui/gtk/engineabout.py:67 ../setup/engineabout.py:67 #, python-format msgid "Author: %s\n" msgstr "Autor: %s\n" -#: ../ui/gtk/engineabout.py:69 -#: ../setup/engineabout.py:69 +#: ../ui/gtk/engineabout.py:69 ../setup/engineabout.py:69 msgid "Description:\n" msgstr "Descripción:\n" @@ -145,12 +144,14 @@ msgstr "El demonio IBUS no fue iniciado. ¿Desea iniciarlo ahora?" #: ../setup/main.py:283 msgid "" -"IBus has been started! If you can not use IBus, please add below lines in $HOME/.bashrc, and relogin your desktop.\n" +"IBus has been started! If you can not use IBus, please add below lines in " +"$HOME/.bashrc, and relogin your desktop.\n" " export GTK_IM_MODULE=ibus\n" " export XMODIFIERS=@im=ibus\n" " export QT_IM_MODULE=ibus" msgstr "" -"¡IBus ha sido iniciado! Si no puede usar IBus, por favor, agregue las siguientes líneas a $HOME/.bashrc, y reingrese a su escritorio.\n" +"¡IBus ha sido iniciado! Si no puede usar IBus, por favor, agregue las " +"siguientes líneas a $HOME/.bashrc, y reingrese a su escritorio.\n" " export GTK_IM_MODULE=ibus\n" " export XMODIFIERS=@im=ibus\n" " export QT_IM_MODULE=ibus" @@ -189,8 +190,7 @@ msgid "Select an input method" msgstr "Seleccione un método de entrada" #. create im name & icon column -#: ../setup/enginetreeview.py:67 -#: ../setup/setup.ui.h:31 +#: ../setup/enginetreeview.py:67 ../setup/setup.ui.h:31 msgid "Input Method" msgstr "Métodos de Entrada" @@ -198,8 +198,7 @@ msgstr "Métodos de Entrada" msgid "Kbd" msgstr "Kbd" -#: ../setup/ibus-setup.desktop.in.h:1 -#: ../setup/setup.ui.h:30 +#: ../setup/ibus-setup.desktop.in.h:1 ../setup/setup.ui.h:30 msgid "IBus Preferences" msgstr "Preferencias de IBus" @@ -233,7 +232,9 @@ msgstr "Habilitar método de entrada en forma predeterminada" #: ../data/ibus.schemas.in.h:7 msgid "Enable input method by default when the application gets input focus" -msgstr "Habilitar método de entrada en forma predeterminada cuando la aplicación en uso solicite alguno" +msgstr "" +"Habilitar método de entrada en forma predeterminada cuando la aplicación en " +"uso solicite alguno" #: ../data/ibus.schemas.in.h:8 msgid "Language panel position" @@ -263,13 +264,11 @@ msgstr "Precargar los motores durante el inicio de ibus" msgid "Prev engine shortcut keys" msgstr "Atajo de teclado para la máquina previa" -#: ../data/ibus.schemas.in.h:15 -#: ../setup/setup.ui.h:40 +#: ../data/ibus.schemas.in.h:15 ../setup/setup.ui.h:40 msgid "Share the same input method among all applications" msgstr "Compartir el mismo método de entrada con todas las aplicaciones" -#: ../data/ibus.schemas.in.h:16 -#: ../setup/setup.ui.h:41 +#: ../data/ibus.schemas.in.h:16 ../setup/setup.ui.h:41 msgid "Show icon on system tray" msgstr "Mostrar un ícono en el área de notificación" @@ -277,29 +276,39 @@ msgstr "Mostrar un ícono en el área de notificación" msgid "Show input method name" msgstr "Mostrar el nombre del método de entrada" -#: ../data/ibus.schemas.in.h:18 -#: ../setup/setup.ui.h:43 +#: ../data/ibus.schemas.in.h:18 ../setup/setup.ui.h:43 msgid "Show input method name on language bar" msgstr "Mostrar el nombre del método de entrada en la barra de idioma" #: ../data/ibus.schemas.in.h:19 -msgid "The behavior of language panel. 0 = Embedded in menu, 1 = Auto hide, 2 = Always show" -msgstr "El comportamiento del panel de idioma. 0 = Incrustado en el menú, 1 = Ocultarlo automáticamente, 2 = Mostrarlo siempre" +msgid "" +"The behavior of language panel. 0 = Embedded in menu, 1 = Auto hide, 2 = " +"Always show" +msgstr "" +"El comportamiento del panel de idioma. 0 = Incrustado en el menú, 1 = " +"Ocultarlo automáticamente, 2 = Mostrarlo siempre" #: ../data/ibus.schemas.in.h:20 -msgid "The position of the language panel. 0 = Top left corner, 1 = Top right corner, 2 = Bottom left corner, 3 = Bottom right corner, 4 = Custom" -msgstr "La posicion el panel de idioma. 0 = esquina superior izquierda, 1 = esquina superior derecha, 2 = esquina inferior izquierda, 3 = esquina inferior derecha, 4 = personalizado" +msgid "" +"The position of the language panel. 0 = Top left corner, 1 = Top right " +"corner, 2 = Bottom left corner, 3 = Bottom right corner, 4 = Custom" +msgstr "" +"La posicion el panel de idioma. 0 = esquina superior izquierda, 1 = esquina " +"superior derecha, 2 = esquina inferior izquierda, 3 = esquina inferior " +"derecha, 4 = personalizado" #: ../data/ibus.schemas.in.h:21 msgid "The shortcut keys for switching to the next input method in the list" -msgstr "Los atajos de teclado para avanzar al siguiente método de entrada de la lista" +msgstr "" +"Los atajos de teclado para avanzar al siguiente método de entrada de la lista" #: ../data/ibus.schemas.in.h:22 msgid "The shortcut keys for switching to the previous input method" -msgstr "Los atajos de teclado para retroceder al método de entrada anterior en la lista" +msgstr "" +"Los atajos de teclado para retroceder al método de entrada anterior en la " +"lista" -#: ../data/ibus.schemas.in.h:23 -#: ../setup/setup.ui.h:49 +#: ../data/ibus.schemas.in.h:23 ../setup/setup.ui.h:49 msgid "The shortcut keys for turning input method on or off" msgstr "Atajo de teclado para encender o apagar el método de entrada" @@ -319,13 +328,11 @@ msgstr "Usar nombre de fuente personalizada para el panel de idioma" msgid "Use global input method" msgstr "Utilizar método de entrada global" -#: ../data/ibus.schemas.in.h:28 -#: ../setup/setup.ui.h:53 +#: ../data/ibus.schemas.in.h:28 ../setup/setup.ui.h:53 msgid "Use system keyboard (XKB) layout" msgstr "Usar el diseño del teclado del sistema (XKB)" -#: ../data/ibus.schemas.in.h:29 -#: ../setup/setup.ui.h:54 +#: ../data/ibus.schemas.in.h:29 ../setup/setup.ui.h:54 msgid "Use system keyboard layout" msgstr "Usar el diseño del teclado del sistema" @@ -379,7 +386,9 @@ msgstr "" #: ../setup/setup.ui.h:17 msgid "Add the selected input method into the enabled input methods" -msgstr "Agregar el método de entrada seleccionado a los métodos de entrada habilitados" +msgstr "" +"Agregar el método de entrada seleccionado a los métodos de entrada " +"habilitados" #: ../setup/setup.ui.h:18 msgid "Advanced" @@ -411,7 +420,9 @@ msgstr "Insertar texto previamente editado en la ventana de la aplicación" #: ../setup/setup.ui.h:25 msgid "Embed the preedit text of input method in the application window" -msgstr "Insertar el texto previamente editado del método de entrada en la ventana de la aplicación" +msgstr "" +"Insertar el texto previamente editado del método de entrada en la ventana de " +"la aplicación" #: ../setup/setup.ui.h:26 msgid "Embedded in menu" @@ -435,11 +446,15 @@ msgstr "Posición del panel de idioma:" #: ../setup/setup.ui.h:33 msgid "Move down the selected input method in the enabled input methods" -msgstr "Mover abajo el método de entrada seleccionado en los métodos de entrada habilitados" +msgstr "" +"Mover abajo el método de entrada seleccionado en los métodos de entrada " +"habilitados" #: ../setup/setup.ui.h:34 msgid "Move up the selected input method in the enabled input methods list" -msgstr "Mover arriba el método de entrada seleccionado en la lista de métodos de entrada habilitados" +msgstr "" +"Mover arriba el método de entrada seleccionado en la lista de métodos de " +"entrada habilitados" #: ../setup/setup.ui.h:35 msgid "Next input method:" @@ -451,11 +466,15 @@ msgstr "Método de entrada anterior:" #: ../setup/setup.ui.h:37 msgid "Remove the selected input method from the enabled input methods" -msgstr "Eliminar el método de entrada seleccionado de los métodos de entrada habilitados" +msgstr "" +"Eliminar el método de entrada seleccionado de los métodos de entrada " +"habilitados" #: ../setup/setup.ui.h:38 msgid "Set the behavior of ibus how to show or hide language bar" -msgstr "Configurar el comportamiento de ibus sobre cómo mostrar u ocultar la barra de idiomas" +msgstr "" +"Configurar el comportamiento de ibus sobre cómo mostrar u ocultar la barra " +"de idiomas" #: ../setup/setup.ui.h:39 msgid "Set the orientation of candidates in lookup table" @@ -467,7 +486,9 @@ msgstr "Mostrar información sobre el método de entrada seleccionado" #: ../setup/setup.ui.h:44 msgid "Show input method's name on language bar when check the checkbox" -msgstr "Mostrar el nombre del método de entrada en la barra de idioma cuando se marque la casilla" +msgstr "" +"Mostrar el nombre del método de entrada en la barra de idioma cuando se " +"marque la casilla" #: ../setup/setup.ui.h:45 msgid "Show language panel:" @@ -479,11 +500,13 @@ msgstr "Iniciar ibus al ingresar" #: ../setup/setup.ui.h:47 msgid "The shortcut keys for switching to next input method in the list" -msgstr "Tecla programada para cambiar al siguiente método de entrada en la lista" +msgstr "" +"Tecla programada para cambiar al siguiente método de entrada en la lista" #: ../setup/setup.ui.h:48 msgid "The shortcut keys for switching to previous input method in the list" -msgstr "Tecla programada para cambiar al método de entrada anterior en la lista" +msgstr "" +"Tecla programada para cambiar al método de entrada anterior en la lista" #: ../setup/setup.ui.h:50 msgid "Top left corner" diff --git a/po/fr.po b/po/fr.po index 587f971..a3ac453 100644 --- a/po/fr.po +++ b/po/fr.po @@ -12,10 +12,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master.fr\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-08-01 01:47+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-08-04 11:45+1000\n" "Last-Translator: Sam Friedmann \n" "Language-Team: French \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -239,7 +240,8 @@ msgstr "Par défaut, activer la méthode d'entrée" #: ../data/ibus.schemas.in.h:7 msgid "Enable input method by default when the application gets input focus" -msgstr "Par défaut, activer la méthode d'entrée lorsque l'application reçoit le focus" +msgstr "" +"Par défaut, activer la méthode d'entrée lorsque l'application reçoit le focus" #: ../data/ibus.schemas.in.h:8 msgid "Language panel position" @@ -304,7 +306,8 @@ msgstr "" #: ../data/ibus.schemas.in.h:21 msgid "The shortcut keys for switching to the next input method in the list" -msgstr "Raccourci clavier pour passer à la méthode d'entrée suivante de la liste" +msgstr "" +"Raccourci clavier pour passer à la méthode d'entrée suivante de la liste" #: ../data/ibus.schemas.in.h:22 msgid "The shortcut keys for switching to the previous input method" @@ -468,7 +471,8 @@ msgstr "Méthode d'entrée précédente :" #: ../setup/setup.ui.h:37 msgid "Remove the selected input method from the enabled input methods" -msgstr "Supprimer la méthode d'entrée selectionnée des méthodes d'entrées actives" +msgstr "" +"Supprimer la méthode d'entrée selectionnée des méthodes d'entrées actives" #: ../setup/setup.ui.h:38 msgid "Set the behavior of ibus how to show or hide language bar" @@ -498,11 +502,13 @@ msgstr "Démarrer IBus lors de la connexion" #: ../setup/setup.ui.h:47 msgid "The shortcut keys for switching to next input method in the list" -msgstr "Raccourci clavier pour passer à la méthode d'entrée suivante de la liste" +msgstr "" +"Raccourci clavier pour passer à la méthode d'entrée suivante de la liste" #: ../setup/setup.ui.h:48 msgid "The shortcut keys for switching to previous input method in the list" -msgstr "Raccourci clavier pour revenir à la méthode d'entrée précédente de la liste" +msgstr "" +"Raccourci clavier pour revenir à la méthode d'entrée précédente de la liste" #: ../setup/setup.ui.h:50 msgid "Top left corner" @@ -523,4 +529,3 @@ msgstr "Verticale" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "Uniquement lorsque active" - diff --git a/po/gu.po b/po/gu.po index cc2be20..2f89ae4 100644 --- a/po/gu.po +++ b/po/gu.po @@ -12,6 +12,7 @@ msgstr "" "PO-Revision-Date: 2010-09-20 12:26+0530\n" "Last-Translator: Sweta Kothari \n" "Language-Team: Gujarati\n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -504,4 +505,3 @@ msgstr "ઊભું" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "જ્યારે સક્રિય હોય" - diff --git a/po/hi.po b/po/hi.po index dfeefc5..c983c14 100644 --- a/po/hi.po +++ b/po/hi.po @@ -8,15 +8,17 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-30 00:45+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-30 16:10+0530\n" "Last-Translator: Rajesh Ranjan \n" "Language-Team: Hindi \n" +"Language: hi\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: KBabel 1.11.4\n" -"Plural-Forms: nplurals=2; plural=(n!=1);\n\n" +"Plural-Forms: nplurals=2; plural=(n!=1);\n" +"\n" "\n" "\n" "\n" @@ -288,7 +290,8 @@ msgstr "भाषा पट्टी पर इनपुट विधि ना msgid "" "The behavior of language panel. 0 = Embedded in menu, 1 = Auto hide, 2 = " "Always show" -msgstr "भाषा फलक का व्यवहार. 0 = मेन्यू में अंतःस्थापित, 1 = स्वतः छिपाएँ, 2 = हमेशा दिखाएँ" +msgstr "" +"भाषा फलक का व्यवहार. 0 = मेन्यू में अंतःस्थापित, 1 = स्वतः छिपाएँ, 2 = हमेशा दिखाएँ" #: ../data/ibus.schemas.in.h:20 msgid "" diff --git a/po/hu.po b/po/hu.po index b055976..ec5f2bf 100644 --- a/po/hu.po +++ b/po/hu.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: IBus master\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2009-04-11 10:58+0200\n" "Last-Translator: Sulyok Péter \n" "Language-Team: Hungarian \n" +"Language: hu\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -89,21 +90,21 @@ msgstr "IBus egy okos bemenő csatorna Linux/Unixhoz" msgid "translator-credits" msgstr "Sulyok Péter , 2009." -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 #, fuzzy msgid "About the input method" msgstr "Bevitel eljárások" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "Bevitel eljárás átváltás" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "Névjegy" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 #, fuzzy msgid "About the Input Method" msgstr "Bevitel eljárások" diff --git a/po/it.po b/po/it.po index eae341f..dec2560 100644 --- a/po/it.po +++ b/po/it.po @@ -11,10 +11,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-28 18:37+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-30 08:36+1000\n" "Last-Translator: \n" "Language-Team: \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -237,7 +238,9 @@ msgstr "Abilita per impostazione predefinita il metodo di input" #: ../data/ibus.schemas.in.h:7 msgid "Enable input method by default when the application gets input focus" -msgstr "Abilita per impostazione predefinita il metodo di input quando le applicazioni ottengono l'input focus" +msgstr "" +"Abilita per impostazione predefinita il metodo di input quando le " +"applicazioni ottengono l'input focus" #: ../data/ibus.schemas.in.h:8 msgid "Language panel position" @@ -302,7 +305,8 @@ msgstr "" #: ../data/ibus.schemas.in.h:21 msgid "The shortcut keys for switching to the next input method in the list" -msgstr "I tasti scorciatoia per passare al metodo di input successivo nell'elenco" +msgstr "" +"I tasti scorciatoia per passare al metodo di input successivo nell'elenco" #: ../data/ibus.schemas.in.h:22 msgid "The shortcut keys for switching to the previous input method" @@ -492,11 +496,13 @@ msgstr "Avvia IBus all'accesso" #: ../setup/setup.ui.h:47 msgid "The shortcut keys for switching to next input method in the list" -msgstr "I tasti scorciatoia per passare al metodo di input successivo nell'elenco" +msgstr "" +"I tasti scorciatoia per passare al metodo di input successivo nell'elenco" #: ../setup/setup.ui.h:48 msgid "The shortcut keys for switching to previous input method in the list" -msgstr "I tasti scorciatoia per passare al metodo di input precedente nell'elenco" +msgstr "" +"I tasti scorciatoia per passare al metodo di input precedente nell'elenco" #: ../setup/setup.ui.h:50 msgid "Top left corner" @@ -517,4 +523,3 @@ msgstr "Verticale" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "Quando attivoB" - diff --git a/po/ja.po b/po/ja.po index 2bf1b19..880291c 100644 --- a/po/ja.po +++ b/po/ja.po @@ -13,10 +13,11 @@ msgid "" msgstr "" "Project-Id-Version: ja\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-30 00:45+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-30 22:20+0900\n" "Last-Translator: Makoto Mizukami \n" "Language-Team: Japanese \n" +"Language: ja\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" diff --git a/po/kn.po b/po/kn.po index a248438..58e1a91 100644 --- a/po/kn.po +++ b/po/kn.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master.kn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-28 06:10+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-28 15:43+0530\n" "Last-Translator: Shankar Prasad \n" "Language-Team: kn_IN \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -376,7 +377,8 @@ msgid "" "You may use up/down buttons to change it." msgstr "" "ಪೂರ್ವನಿಯೋಜಿತ ಇನ್‌ಪುಟ್‌ ವಿಧಾನವು ಪಟ್ಟಿಯ ಮೇಲ್ಬಾಗದಲ್ಲಿದೆ.\n" -"ಅದನ್ನು ಬದಲಾಯಿಸಲು ನೀವು ಮೇಲೆ/ಕೆಳಗಿನ ಬಾಣದ ಗುರುತಿನ ಗುಂಡಿಗಳನ್ನು ಬಳಸಬಹುದು." +"ಅದನ್ನು ಬದಲಾಯಿಸಲು ನೀವು ಮೇಲೆ/ಕೆಳಗಿನ ಬಾಣದ ಗುರುತಿನ ಗುಂಡಿಗಳನ್ನು ಬಳಸಬಹುದು." #: ../setup/setup.ui.h:17 msgid "Add the selected input method into the enabled input methods" @@ -459,7 +461,8 @@ msgstr "" #: ../setup/setup.ui.h:38 msgid "Set the behavior of ibus how to show or hide language bar" -msgstr "ಭಾಷಾ ಪಟ್ಟಿಕೆಯನ್ನು ಹೇಗೆ ತೋರಿಸಬೇಕು ಅಥವ ಅಡಗಿಸಬೇಕು ಎನ್ನುವ ibus ನ ವರ್ತನೆಯನ್ನು ಹೊಂದಿಸಿ" +msgstr "" +"ಭಾಷಾ ಪಟ್ಟಿಕೆಯನ್ನು ಹೇಗೆ ತೋರಿಸಬೇಕು ಅಥವ ಅಡಗಿಸಬೇಕು ಎನ್ನುವ ibus ನ ವರ್ತನೆಯನ್ನು ಹೊಂದಿಸಿ" #: ../setup/setup.ui.h:39 msgid "Set the orientation of candidates in lookup table" diff --git a/po/ko.po b/po/ko.po index 6881e81..6365ce8 100644 --- a/po/ko.po +++ b/po/ko.po @@ -8,10 +8,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master.ko\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-08-02 08:23+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-08-03 15:01+1000\n" "Last-Translator: \n" "Language-Team: Korean \n" +"Language: ko\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -503,4 +504,3 @@ msgstr "세로" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "활성화 되었을 때" - diff --git a/po/ml.po b/po/ml.po index ee920ff..5057e76 100644 --- a/po/ml.po +++ b/po/ml.po @@ -9,10 +9,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master.ml\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-08-02 08:23+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-08-02 17:16+0530\n" "Last-Translator: \n" "Language-Team: \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -480,7 +481,8 @@ msgstr "പ്രവേശിക്കുമ്പോള്‍ തന്നെ i #: ../setup/setup.ui.h:47 msgid "The shortcut keys for switching to next input method in the list" -msgstr "അടുത്ത ഇന്‍പുട്ട് മെഥേഡ് സംവിധാനത്തിലേക്ക് മാറ്റുന്നതിനായി അടുത്ത സംവിധാനത്തിനുള്ള എളുപ്പവഴി" +msgstr "" +"അടുത്ത ഇന്‍പുട്ട് മെഥേഡ് സംവിധാനത്തിലേക്ക് മാറ്റുന്നതിനായി അടുത്ത സംവിധാനത്തിനുള്ള എളുപ്പവഴി" #: ../setup/setup.ui.h:48 msgid "The shortcut keys for switching to previous input method in the list" @@ -507,4 +509,3 @@ msgstr "നേരെയുള്ള" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "സജീവമാകുമ്പോള്‍" - diff --git a/po/mr.po b/po/mr.po index c88d764..83b4421 100644 --- a/po/mr.po +++ b/po/mr.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: mr\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-30 00:45+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-30 08:28+0530\n" "Last-Translator: Sandeep Shedmake \n" "Language-Team: Marathi \n" +"Language: mr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -87,7 +88,9 @@ msgstr "Linux/Unix करीता IBus हे एक हुशार इनप #: ../ui/gtk/panel.py:492 msgid "translator-credits" -msgstr "संदिप शेडमाके , 2009; संदिप शेडमाके , 2009, 2010." +msgstr "" +"संदिप शेडमाके , 2009; संदिप शेडमाके , 2009, 2010." #: ../ui/gtk/languagebar.py:108 msgid "About the input method" @@ -502,4 +505,3 @@ msgstr "उभे" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "सक्रीय असल्यावर" - diff --git a/po/or.po b/po/or.po index 1097f0d..42096f2 100644 --- a/po/or.po +++ b/po/or.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master.or\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-30 00:45+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-30 13:19+0530\n" "Last-Translator: Manoj Kumar Giri \n" "Language-Team: Oriya \n" +"Language: or\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -240,7 +241,8 @@ msgstr "ପୂର୍ବନିର୍ଦ୍ଧାରିତ ଭାବରେ ନି #: ../data/ibus.schemas.in.h:7 msgid "Enable input method by default when the application gets input focus" -msgstr "ପୂର୍ବନିର୍ଦ୍ଧାରିତ ଭାବରେ ନିବେଶ ପ୍ରଣାଳୀକୁ ସକ୍ରିୟ କରନ୍ତୁ ଯେତେବେଳେ ପ୍ରୟୋଗକୁ ନିବେଶ ଲକ୍ଷ୍ଯ ମିଳିଥାଏ" +msgstr "" +"ପୂର୍ବନିର୍ଦ୍ଧାରିତ ଭାବରେ ନିବେଶ ପ୍ରଣାଳୀକୁ ସକ୍ରିୟ କରନ୍ତୁ ଯେତେବେଳେ ପ୍ରୟୋଗକୁ ନିବେଶ ଲକ୍ଷ୍ଯ ମିଳିଥାଏ" #: ../data/ibus.schemas.in.h:8 msgid "Language panel position" @@ -513,4 +515,3 @@ msgstr "ଭୂଲମ୍ବ" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "ସକ୍ରିୟ ଥିବା ସମୟରେ" - diff --git a/po/pa.po b/po/pa.po index d1707d0..abb90e0 100644 --- a/po/pa.po +++ b/po/pa.po @@ -8,10 +8,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-05-05 16:23+0530\n" "Last-Translator: Jaswinder Singh \n" "Language-Team: Punjabi/Panjabi \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -94,20 +95,20 @@ msgstr "" "ਅਮਨਪਰੀਤ ਸਿੰਘ ਆਲਮ ੨੦੦੮-੨੦੦੯\n" "http://www.satluj.com/" -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 msgid "About the input method" msgstr "ਇੰਪੁੱਟ ਢੰਗ ਬਾਰੇ" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "ਇੰਪੁੱਟ ਢੰਗ ਬਦਲੋ" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "ਇਸ ਬਾਰੇ" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 msgid "About the Input Method" msgstr "ਇੰਪੁੱਟ ਢੰਗ ਬਾਰੇ" diff --git a/po/pl.po b/po/pl.po index 43428b3..d28d511 100644 --- a/po/pl.po +++ b/po/pl.po @@ -5,10 +5,11 @@ msgid "" msgstr "" "Project-Id-Version: pl\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-05-14 00:15+0200\n" "Last-Translator: Piotr Drąg \n" "Language-Team: Polish \n" +"Language: pl\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -87,20 +88,20 @@ msgstr "iBus jest inteligentną magistralą wprowadzania dla systemu Linux/UNIX. msgid "translator-credits" msgstr "Piotr Drąg , 2009" -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 msgid "About the input method" msgstr "O metodzie wprowadzania" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "Przełącz metodę wprowadzania" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "O programie" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 msgid "About the Input Method" msgstr "O metodzie wprowadzania" diff --git a/po/pt_BR.po b/po/pt_BR.po index f5626f5..5d6a34d 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -11,10 +11,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master.pt_BR\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-30 00:45+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-30 11:10+1000\n" "Last-Translator: Glaucia Cintra \n" "Language-Team: Portuguese \n" +"Language: pt\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -234,7 +235,9 @@ msgstr "Habilitar método de entrada por padrão" #: ../data/ibus.schemas.in.h:7 msgid "Enable input method by default when the application gets input focus" -msgstr "Habilitar método de entrada por padrão quando o aplicativo obtiver o foco de entradas" +msgstr "" +"Habilitar método de entrada por padrão quando o aplicativo obtiver o foco de " +"entradas" #: ../data/ibus.schemas.in.h:8 msgid "Language panel position" @@ -299,7 +302,8 @@ msgstr "" #: ../data/ibus.schemas.in.h:21 msgid "The shortcut keys for switching to the next input method in the list" -msgstr "As teclas de atalho para alteração ao próximo método de entrada na lista " +msgstr "" +"As teclas de atalho para alteração ao próximo método de entrada na lista " #: ../data/ibus.schemas.in.h:22 msgid "The shortcut keys for switching to the previous input method" @@ -384,7 +388,8 @@ msgstr "" #: ../setup/setup.ui.h:17 msgid "Add the selected input method into the enabled input methods" -msgstr "Adicione o método de entrada selecionado nos métodos de entrada ativados" +msgstr "" +"Adicione o método de entrada selecionado nos métodos de entrada ativados" #: ../setup/setup.ui.h:18 msgid "Advanced" @@ -416,7 +421,8 @@ msgstr "Embutir texto de pré-edição na janela do aplicativo " #: ../setup/setup.ui.h:25 msgid "Embed the preedit text of input method in the application window" -msgstr "Embutir o texto de pré-edição do método de entrada na janela do aplicativo" +msgstr "" +"Embutir o texto de pré-edição do método de entrada na janela do aplicativo" #: ../setup/setup.ui.h:26 msgid "Embedded in menu" @@ -494,7 +500,8 @@ msgstr "Inicie o ibus na conexão " #: ../setup/setup.ui.h:47 msgid "The shortcut keys for switching to next input method in the list" -msgstr "As teclas de atalho para alteração ao próximo método de entrada na lista" +msgstr "" +"As teclas de atalho para alteração ao próximo método de entrada na lista" #: ../setup/setup.ui.h:48 msgid "The shortcut keys for switching to previous input method in the list" @@ -519,4 +526,3 @@ msgstr "Vertical" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "Quando ativado" - diff --git a/po/ru.po b/po/ru.po index 0734ebe..72a1ee7 100644 --- a/po/ru.po +++ b/po/ru.po @@ -8,14 +8,16 @@ msgid "" msgstr "" "Project-Id-Version: ru\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-29 23:22+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-30 10:25\n" "Last-Translator: Yulia \n" "Language-Team: Russian\n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Generator: KBabel 1.11.4\n" #: ../bus/ibus.desktop.in.h:1 @@ -55,8 +57,8 @@ msgid "" "Some input methods have been installed, removed or updated. Please restart " "ibus input platform." msgstr "" -"Методы ввода были установлены, удалены или обновлены. " -"Перезапустите платформу ввода iBus." +"Методы ввода были установлены, удалены или обновлены. Перезапустите " +"платформу ввода iBus." #: ../ui/gtk/main.py:62 msgid "Restart Now" @@ -234,7 +236,8 @@ msgstr "Включить метод ввода по умолчанию" #: ../data/ibus.schemas.in.h:7 msgid "Enable input method by default when the application gets input focus" -msgstr "Включить метод ввода по умолчанию при получении приложением фокуса ввода" +msgstr "" +"Включить метод ввода по умолчанию при получении приложением фокуса ввода" #: ../data/ibus.schemas.in.h:8 msgid "Language panel position" @@ -470,7 +473,8 @@ msgstr "Показать информацию о выбранном методе #: ../setup/setup.ui.h:44 msgid "Show input method's name on language bar when check the checkbox" -msgstr "Показывать название метода ввода на языковой панели, когда пункт выбран" +msgstr "" +"Показывать название метода ввода на языковой панели, когда пункт выбран" #: ../setup/setup.ui.h:45 msgid "Show language panel:" @@ -507,4 +511,3 @@ msgstr "Вертикально" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "Когда активно" - diff --git a/po/sr.po b/po/sr.po index b956b4a..ee74ae3 100644 --- a/po/sr.po +++ b/po/sr.po @@ -7,15 +7,16 @@ msgid "" msgstr "" "Project-Id-Version: ibus\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2009-04-01 19:58+0100\n" "Last-Translator: MiloÅ¡ Komarčević \n" "Language-Team: Serbian \n" +"Language: sr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%" -"10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" #: ../bus/ibus.desktop.in.h:1 msgid "IBus" @@ -92,22 +93,22 @@ msgstr "IBus је интелигентна магистрала уноса за msgid "translator-credits" msgstr "Serbian " -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 #, fuzzy msgid "About the input method" msgstr "Методе уноса" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 #, fuzzy msgid "Switch input method" msgstr "Нема методе уноса" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "О програму" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 #, fuzzy msgid "About the Input Method" msgstr "Методе уноса" diff --git a/po/sr@latin.po b/po/sr@latin.po index 5b9523d..0f002bb 100644 --- a/po/sr@latin.po +++ b/po/sr@latin.po @@ -7,15 +7,16 @@ msgid "" msgstr "" "Project-Id-Version: ibus\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2009-04-01 19:58+0100\n" "Last-Translator: MiloÅ¡ Komarčević \n" "Language-Team: Serbian \n" +"Language: sr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%" -"10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" #: ../bus/ibus.desktop.in.h:1 msgid "IBus" @@ -92,22 +93,22 @@ msgstr "IBus je inteligentna magistrala unosa za Linux/Unix." msgid "translator-credits" msgstr "Serbian " -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 #, fuzzy msgid "About the input method" msgstr "Metode unosa" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 #, fuzzy msgid "Switch input method" msgstr "Nema metode unosa" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "O programu" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 #, fuzzy msgid "About the Input Method" msgstr "Metode unosa" diff --git a/po/ta.po b/po/ta.po index b62c470..741f30d 100644 --- a/po/ta.po +++ b/po/ta.po @@ -8,16 +8,16 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master.ta\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-30 00:45+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-30 12:32+0530\n" "Last-Translator: I Felix \n" "Language-Team: Tamil \n" +"Language: ta\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Lokalize 1.0\n" -"Plural-Forms: nplurals=2; plural=(n!=1);\\n" -"\n" +"Plural-Forms: nplurals=2; plural=(n!=1);\\n\n" #: ../bus/ibus.desktop.in.h:1 msgid "IBus" diff --git a/po/te.po b/po/te.po index 74a4461..f2fbb66 100644 --- a/po/te.po +++ b/po/te.po @@ -7,15 +7,17 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master.te\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-30 00:45+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-30 14:17+0530\n" "Last-Translator: Krishna Babu K \n" "Language-Team: Telugu \n" +"Language: te\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: KBabel 1.11.4\n" -"Plural-Forms: nplurals=2; plural=(n!=1);\n\n" +"Plural-Forms: nplurals=2; plural=(n!=1);\n" +"\n" "\n" "\n" "\n" @@ -511,4 +513,3 @@ msgstr "వెర్టికల్" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "క్రియాశీలముగా వున్నప్పుడు" - diff --git a/po/vi.po b/po/vi.po index 00ed2b8..7691361 100644 --- a/po/vi.po +++ b/po/vi.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: data 1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-06-01 13:17+0700\n" "Last-Translator: Lê Quốc Tuấn \n" "Language-Team: Vietnamese\n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -90,20 +91,20 @@ msgstr "IBus là một bộ gõ thông minh cho Linux/Unix." msgid "translator-credits" msgstr "Lê Quốc Tuấn " -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 msgid "About the input method" msgstr "Giới thiệu về kiểu gõ" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "Chuyển kiểu gõ" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "Giới thiệu" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 msgid "About the Input Method" msgstr "Giới thiệu về kiểu gõ" diff --git a/po/zh_CN.po b/po/zh_CN.po index f0f0689..5501fdc 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -9,10 +9,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus.master\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-07-29 23:22+0000\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-07-30 10:43+1000\n" "Last-Translator: Leah Liu \n" "Language-Team: Wei Liu\n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -500,4 +501,3 @@ msgstr "竖直" #: ../setup/setup.ui.h:56 msgid "When active" msgstr "活动时" - diff --git a/po/zh_HK.po b/po/zh_HK.po index bcecb8c..92b09b8 100644 --- a/po/zh_HK.po +++ b/po/zh_HK.po @@ -9,10 +9,11 @@ msgid "" msgstr "" "Project-Id-Version: zh_TW\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-23 13:32+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-05-06 13:25+1000\n" "Last-Translator: Terry Chuang \n" "Language-Team: Traditional Chinese \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -96,20 +97,20 @@ msgstr "" "Ding-Yi Chen 陳定彞 , 2009\n" "Cheng-Chia Tseng , 2010" -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 msgid "About the input method" msgstr "關於輸入法" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "切換輸入法" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "關於" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 msgid "About the Input Method" msgstr "關於輸入法" diff --git a/po/zh_TW.po b/po/zh_TW.po index 51316d1..a4c1c88 100644 --- a/po/zh_TW.po +++ b/po/zh_TW.po @@ -10,10 +10,11 @@ msgid "" msgstr "" "Project-Id-Version: ibus\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-06-28 13:15+0800\n" +"POT-Creation-Date: 2010-08-07 10:22+0800\n" "PO-Revision-Date: 2010-06-28 13:10+0800\n" "Last-Translator: Cheng-Chia Tseng \n" "Language-Team: chinese-l10n \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -91,20 +92,20 @@ msgstr "" "Ding-Yi Chen 陳定彞 , 2009.\n" "Cheng-Chia Tseng , 2010." -#: ../ui/gtk/languagebar.py:107 +#: ../ui/gtk/languagebar.py:108 msgid "About the input method" msgstr "關於輸入法" -#: ../ui/gtk/languagebar.py:215 +#: ../ui/gtk/languagebar.py:216 msgid "Switch input method" msgstr "切換輸入法" -#: ../ui/gtk/languagebar.py:358 ../ui/gtk/engineabout.py:35 +#: ../ui/gtk/languagebar.py:359 ../ui/gtk/engineabout.py:35 #: ../setup/engineabout.py:35 ../setup/setup.ui.h:16 msgid "About" msgstr "關於" -#: ../ui/gtk/languagebar.py:362 +#: ../ui/gtk/languagebar.py:363 msgid "About the Input Method" msgstr "關於輸入法" diff --git a/src/Makefile.am b/src/Makefile.am index c45a588..6ffdeb7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,130 +20,154 @@ # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA +NULL = + +SUBDIRS = . tests + +libibus = libibus-2.0.la + +# gobject introspection -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_SCANNER_ARGS = INTROSPECTION_COMPILER_ARGS = \ - --includedir=$(srcdir) \ - --includedir=. \ + --includedir=$(srcdir) \ + --includedir=. \ $(NULL) INTROSPECTION_GIRS = CLEANFILES = - -INCLUDES = \ - -I$(top_srcdir) \ +# C preprocessor flags +AM_CPPFLAGS = \ + -DG_LOG_DOMAIN=\"IBUS\" \ + @GLIB2_CFLAGS@ \ + @GOBJECT2_CFLAGS@ \ + @GIO2_CFLAGS@ \ + -DIBUS_DATA_DIR=\"$(pkgdatadir)\" \ + -DIBUS_COMPILATION \ $(NULL) # ibus library -ibustargetlib = libibus.la -lib_LTLIBRARIES = $(ibustargetlib) -ibus_built_public_h_sources = \ - ibusmarshalers.h \ - ibusenumtypes.h \ - $(NULl) -ibus_built_c_sources = \ - ibusmarshalers.c \ - ibusenumtypes.c \ - $(NULL) -ibus_built_sources = \ - $(ibus_built_public_h_sources) \ - $(ibus_built_c_sources) \ - $(NULL) -ibus_public_h_sources = \ - ibus.h \ - ibusdbus.h \ - ibusversion.h \ - ibusshare.h \ - ibusdebug.h \ - ibusobject.h \ - ibusserializable.h \ - ibusconnection.h \ - ibusserver.h \ - ibusproxy.h \ - ibusservice.h \ - ibusfactory.h \ - ibusengine.h \ - ibustext.h \ - ibuskeymap.h \ - ibusattribute.h \ - ibusattrlist.h \ - ibusproperty.h \ - ibusproplist.h \ - ibuslookuptable.h \ - ibusinputcontext.h \ - ibusconfig.h \ - ibusconfigservice.h \ - ibuspanelservice.h \ - ibusmessage.h \ - ibuspendingcall.h \ - ibuserror.h \ - ibuskeysyms.h \ - ibustypes.h \ - ibusbus.h \ - ibushotkey.h \ - ibusxml.h \ - ibusenginedesc.h \ - ibusobservedpath.h \ - ibuscomponent.h \ - ibusmainloop.h \ +lib_LTLIBRARIES = $(libibus) + +libibus_2_0_la_LIBADD = \ + @GLIB2_LIBS@ \ + @GOBJECT2_LIBS@ \ + @GIO2_LIBS@ \ $(NULL) -ibus_h_sources = \ - ibusinternal.h \ - ibusconfigprivate.h \ - keyname-table.h \ - $(ibus_public_h_sources) \ +libibus_2_0_la_LDFLAGS = \ + -no-undefined \ + -export-symbols-regex "ibus_.*" \ + -version-info @LT_VERSION_INFO@ \ $(NULL) -ibus_c_sources = \ - ibusshare.c \ - ibusinternal.c \ - ibusobject.c \ - ibusserializable.c \ - ibusconnection.c \ - ibusserver.c \ - ibusproxy.c \ - ibusservice.c \ - ibusfactory.c \ - ibusengine.c \ - ibustext.c \ - ibuskeymap.c \ - ibusattribute.c \ - ibusattrlist.c \ - ibusproperty.c \ - ibusproplist.c \ - ibuslookuptable.c \ - ibusinputcontext.c \ - ibusconfig.c \ - ibusconfigservice.c \ - ibuspanelservice.c \ - ibusmessage.c \ - ibuspendingcall.c \ - ibuserror.c \ - ibusbus.c \ - ibuskeynames.c \ - ibushotkey.c \ - ibusxml.c \ - ibusenginedesc.c \ - ibusobservedpath.c \ - ibuscomponent.c \ - ibusmainloop.c \ + +ibus_sources = \ + ibusshare.c \ + ibusobject.c \ + ibusserializable.c \ + ibusproxy.c \ + ibusservice.c \ + ibusfactory.c \ + ibusengine.c \ + ibustext.c \ + ibuskeymap.c \ + ibusattribute.c \ + ibusattrlist.c \ + ibusproperty.c \ + ibusproplist.c \ + ibuslookuptable.c \ + ibusinputcontext.c \ + ibusconfig.c \ + ibusconfigservice.c \ + ibuspanelservice.c \ + ibusbus.c \ + ibuskeynames.c \ + ibushotkey.c \ + ibusxml.c \ + ibusenginedesc.c \ + ibusobservedpath.c \ + ibuscomponent.c \ + $(NULL) +libibus_2_0_la_SOURCES = \ + $(ibus_sources) \ + ibusmarshalers.c \ + ibusenumtypes.c \ + $(NULL) +ibus_marshalers_sources = \ + ibusmarshalers.h \ + ibusmarshalers.c \ + $(NULL) +ibus_enumtypes_sources = \ + ibusenumtypes.h \ + ibusenumtypes.c \ + $(NULL) +ibus_headers = \ + ibus.h \ + ibusdbus.h \ + ibusversion.h \ + ibusshare.h \ + ibusdebug.h \ + ibusobject.h \ + ibusserializable.h \ + ibusproxy.h \ + ibusservice.h \ + ibusfactory.h \ + ibusengine.h \ + ibustext.h \ + ibuskeymap.h \ + ibusattribute.h \ + ibusattrlist.h \ + ibusproperty.h \ + ibusproplist.h \ + ibuslookuptable.h \ + ibusinputcontext.h \ + ibusconfig.h \ + ibusconfigservice.h \ + ibuspanelservice.h \ + ibuskeysyms.h \ + ibustypes.h \ + ibusbus.h \ + ibushotkey.h \ + ibusxml.h \ + ibusenginedesc.h \ + ibusobservedpath.h \ + ibuscomponent.h \ + $(NULL) +ibusincludedir = $(includedir)/ibus-2.0 +ibusinclude_HEADERS = \ + $(ibus_headers) \ + ibusenumtypes.h \ + $(NULL) + +ibus_privite_headers = \ + ibusconfigprivate.h \ + ibusinternal.h \ + keyname-table.h \ + $(NULL) +noinst_HEADERS = \ + $(ibus_privite_headers) \ + $(NULL) + +BUILT_SOURCES = \ + ibusmarshalers.h \ + ibusmarshalers.c \ + ibusenumtypes.h \ + ibusenumtypes.c \ $(NULL) -ibusincludedir = $(includedir)/ibus-1.0 if HAVE_INTROSPECTION - -introspection_files = \ - $(ibus_public_h_sources) \ - $(ibus_c_sources) \ - ibusenumtypes.c \ - ibusenumtypes.h \ +introspection_files = \ + $(ibus_public_h_sources) \ + $(ibus_c_sources) \ + ibusenumtypes.c \ + ibusenumtypes.h \ $(NULL) -IBus-1.0.gir: $(ibustargetlib) Makefile -IBus_1_0_gir_SCANNERFLAGS = --pkg=glib-2.0 $(IBUS_GIR_SCANNERFLAGS) -IBus_1_0_gir_INCLUDES = GLib-2.0 GObject-2.0 -IBus_1_0_gir_LIBS = $(ibustargetlib) -IBus_1_0_gir_FILES = $(addprefix $(srcdir)/,$(introspection_files)) -IBus_1_0_gir_CFLAGS = $(INCLUDES) -INTROSPECTION_GIRS += IBus-1.0.gir +IBus-2.0.gir: $(libibus) Makefile +IBus_2_0_gir_SCANNERFLAGS = --pkg=glib-2.0 $(IBUS_GIR_SCANNERFLAGS) +IBus_2_0_gir_INCLUDES = GLib-2.0 GObject-2.0 +IBus_2_0_gir_LIBS = $(libibus) +IBus_2_0_gir_FILES = $(addprefix $(srcdir)/,$(introspection_files)) +IBus_2_0_gir_CFLAGS = +INTROSPECTION_GIRS += IBus-2.0.gir girdir = $(datadir)/gir-1.0 dist_gir_DATA = $(INTROSPECTION_GIRS) @@ -154,132 +178,44 @@ typelibs_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) CLEANFILES += $(dist_gir_DATA) $(typelibs_DATA) endif -ibusinclude_HEADERS = \ - $(ibus_public_h_sources) \ - $(ibus_built_public_h_sources) \ - $(NULL) -libibus_la_SOURCES = \ - $(ibus_h_sources) \ - $(ibus_c_sources) \ - $(NULL) -nodist_libibus_la_SOURCES = \ - $(ibus_built_h_sources) \ - $(ibus_built_c_sources) \ - $(NULL) -libibus_la_CFLAGS = \ - @X11_CFLAGS@ \ - @GLIB2_CFLAGS@ \ - @GOBJECT2_CFLAGS@ \ - @GIO2_CFLAGS@ \ - @DBUS_CFLAGS@ \ - -DG_LOG_DOMAIN=\"IBUS\" \ - -DIBUS_DATA_DIR=\"$(pkgdatadir)\" \ - $(NULL) -libibus_la_LIBADD = \ - @X11_LIBS@ \ - @GLIB2_LIBS@ \ - @GOBJECT2_LIBS@ \ - @GIO2_LIBS@ \ - @DBUS_LIBS@ \ - $(NULL) -libibus_la_LDFLAGS = \ - -export-symbols-regex "ibus_.*" \ - -version-info @LT_VERSION_INFO@ \ - $(NULL) - -BUILT_SOURCES = \ - $(ibus_built_sources) \ - $(NULL) - - -# test programs -DEPS = \ - libibus.la \ - $(NULL) -AM_CFLAGS = \ - @X11_CFLAGS@ \ - @GLIB2_CFLAGS@ \ - @GOBJECT2_CFLAGS@ \ - @GIO2_CFLAGS@ \ - @DBUS_CFLAGS@ \ - -DG_LOG_DOMAIN=\"IBUS\" \ - $(NULL) -AM_LDADD = \ - $(DEPS) \ - @GLIB2_LIBS@ \ - @GOBJECT2_LIBS@ \ - $(NULL) - -TESTS = \ - test-bus \ - test-text \ - test-keymap \ - test-keynames \ - test-attribute \ - test-lookuptable \ - test-global-engine \ - $(NULL) -noinst_PROGRAMS = $(TESTS) -test_bus_DEPENDENCIES = $(DEPS) -test_text_DEPENDENCIES = $(DEPS) -test_keymap_DEPENDENCIES = $(DEPS) -test_keynames_DEPENDENCIES = $(DEPS) -test_attribute_DEPENDENCIES = $(DEPS) -test_lookuptable_DEPENDENCIES = $(DEPS) -test_global_engine_DEPENDENCIES = $(DEPS) -test_bus_LDADD = $(AM_LDADD) -test_text_LDADD = $(AM_LDADD) -test_keymap_LDADD = $(AM_LDADD) -test_keynames_LDADD = $(AM_LDADD) -test_attribute_LDADD = $(AM_LDADD) -test_lookuptable_LDADD = $(AM_LDADD) -test_global_engine_LDADD = $(AM_LDADD) - # gen enum types -ibusenumtypes.h: stamp-ibusenumtypes.h - @true -stamp-ibusenumtypes.h: $(ibus_public_h_sources) ibusenumtypes.h.template - @( cd $(srcdir) && $(GLIB_MKENUMS) --template ibusenumtypes.h.template \ - $(ibus_public_h_sources) ) | sed 's/i_bus_/ibus_/g' | sed 's/I_TYPE_BUS_/IBUS_TYPE_/g' >> xgen-geth \ - && (cmp -s xgen-geth ibusenumtypes.h || cp xgen-geth ibusenumtypes.h ) \ - && rm -f xgen-geth \ - && echo timestamp > $(@F) -ibusenumtypes.c: $(ibus_public_h_sources) ibusenumtypes.c.template - $(AM_V_GEN) \ - ( cd $(srcdir) && $(GLIB_MKENUMS) --template ibusenumtypes.c.template \ - $(ibus_public_h_sources) ) | sed 's/i_bus_/ibus_/g' | sed 's/I_TYPE_BUS_/IBUS_TYPE_/g' > xgen-getc \ - && cp xgen-getc ibusenumtypes.c \ - && rm -f xgen-getc +ibusenumtypes.h: $(ibus_headers) ibusenumtypes.h.template + $(AM_V_GEN) ( top_builddir=`cd $(top_builddir) && pwd`; \ + cd $(srcdir) && $(GLIB_MKENUMS) --template ibusenumtypes.h.template $(ibus_headers) | \ + sed 's/i_bus_/ibus_/g' | \ + sed 's/I_TYPE_BUS_/IBUS_TYPE_/g') > \ + ibusenumtypes.h.tmp && mv ibusenumtypes.h.tmp ibusenumtypes.h + +ibusenumtypes.c: $(ibus_headers) ibusenumtypes.c.template + $(AM_V_GEN) ( top_builddir=`cd $(top_builddir) && pwd`; \ + cd $(srcdir) && $(GLIB_MKENUMS) --template ibusenumtypes.c.template $(ibus_headers) | \ + sed 's/i_bus_/ibus_/g' | \ + sed 's/I_TYPE_BUS_/IBUS_TYPE_/g') > \ + ibusenumtypes.c.tmp && mv ibusenumtypes.c.tmp ibusenumtypes.c # gen marshal -ibusmarshalers.h: stamp-ibusmarshalers.h - @true -stamp-ibusmarshalers.h: ibusmarshalers.list - @$(GLIB_GENMARSHAL) --prefix=ibus_marshal $(srcdir)/ibusmarshalers.list --header >> xgen-gmh \ - && (cmp -s xgen-gmh ibusmarshalers.h || cp xgen-gmh ibusmarshalers.h) \ - && rm -f xgen-gmh \ - && echo timestamp > $(@F) -ibusmarshalers.c: ibusmarshalers.list - $(AM_V_GEN) \ - (echo "#include \"ibusmarshalers.h\""; \ - $(GLIB_GENMARSHAL) --prefix=ibus_marshal $(srcdir)/ibusmarshalers.list --body; \ - echo ) >> xgen-gmc \ - && cp xgen-gmc ibusmarshalers.c \ - && rm -f xgen-gmc +ibusmarshalers.h: ibusmarshalers.list + $(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=_ibus_marshal $(srcdir)/ibusmarshalers.list --header --internal > $@.tmp && \ + mv $@.tmp $@ + +ibusmarshalers.c: ibusmarshalers.h ibusmarshalers.list + $(AM_V_GEN) (echo "#include \"ibusmarshalers.h\""; \ + $(GLIB_GENMARSHAL) --prefix=_ibus_marshal $(srcdir)/ibusmarshalers.list --body --internal) > $@.tmp && \ + mv $@.tmp $@ -EXTRA_DIST = \ - ibusversion.h.in \ - ibusmarshalers.list \ - ibusenumtypes.h.template \ - ibusenumtypes.c.template \ +EXTRA_DIST = \ + ibusversion.h.in \ + ibusmarshalers.list \ + ibusenumtypes.h.template \ + ibusenumtypes.c.template \ $(NULL) -CLEANFILES += \ - $(BUILT_SOURCES) \ - stamp-ibusmarshalers.h \ - stamp-ibusenumtypes.h \ +CLEANFILES += \ + $(BUILT_SOURCES) \ + stamp-ibusmarshalers.h \ + stamp-ibusenumtypes.h \ $(NULL) -DISTCLEANFILES = \ - ibusversion.h \ +DISTCLEANFILES = \ + ibusversion.h \ $(NULL) diff --git a/src/ibus.h b/src/ibus.h index 8b01123..5c0bdd7 100644 --- a/src/ibus.h +++ b/src/ibus.h @@ -22,16 +22,15 @@ #ifndef __IBUS_H_ #define __IBUS_H_ +#define __IBUS_H_INSIDE__ + #include -#include #include #include #include #include #include #include -#include -#include #include #include #include @@ -42,9 +41,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -53,7 +49,8 @@ #include #include #include -#include + +#undef __IBUS_H_INSIDE__ #endif diff --git a/src/ibusattribute.c b/src/ibusattribute.c index 85ada31..816bcee 100644 --- a/src/ibusattribute.c +++ b/src/ibusattribute.c @@ -24,26 +24,22 @@ /* functions prototype */ // static void ibus_attribute_destroy (IBusAttribute *attr); static gboolean ibus_attribute_serialize (IBusAttribute *attr, - IBusMessageIter *iter); -static gboolean ibus_attribute_deserialize (IBusAttribute *attr, - IBusMessageIter *iter); + GVariantBuilder *builder); +static gint ibus_attribute_deserialize (IBusAttribute *attr, + GVariant *variant); static gboolean ibus_attribute_copy (IBusAttribute *dest, const IBusAttribute *src); G_DEFINE_TYPE (IBusAttribute, ibus_attribute, IBUS_TYPE_SERIALIZABLE) static void -ibus_attribute_class_init (IBusAttributeClass *klass) +ibus_attribute_class_init (IBusAttributeClass *class) { - IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (klass); - - // object_class->destroy = (IBusObjectDestroyFunc) ibus_attribute_destroy; + IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class); serializable_class->serialize = (IBusSerializableSerializeFunc) ibus_attribute_serialize; serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_attribute_deserialize; serializable_class->copy = (IBusSerializableCopyFunc) ibus_attribute_copy; - - g_string_append (serializable_class->signature, "uuuu"); } static void @@ -51,66 +47,38 @@ ibus_attribute_init (IBusAttribute *attr) { } -// static void -// ibus_attribute_destroy (IBusAttribute *attr) -// { -// IBUS_OBJECT (ibus_attribute_parent_class)->destroy ((IBusObject *)attr); -// } - static gboolean ibus_attribute_serialize (IBusAttribute *attr, - IBusMessageIter *iter) + GVariantBuilder *builder) { gboolean retval; - retval = IBUS_SERIALIZABLE_CLASS (ibus_attribute_parent_class)->serialize ((IBusSerializable *) attr, iter); - g_return_val_if_fail (retval, FALSE); - - g_return_val_if_fail (IBUS_IS_ATTRIBUTE (attr), FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_UINT, &attr->type); + retval = IBUS_SERIALIZABLE_CLASS (ibus_attribute_parent_class)->serialize ((IBusSerializable *) attr, builder); g_return_val_if_fail (retval, FALSE); - retval = ibus_message_iter_append (iter, G_TYPE_UINT, &attr->value); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_UINT, &attr->start_index); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_UINT, &attr->end_index); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "u", attr->type); + g_variant_builder_add (builder, "u", attr->value); + g_variant_builder_add (builder, "u", attr->start_index); + g_variant_builder_add (builder, "u", attr->end_index); return TRUE; } -static gboolean -ibus_attribute_deserialize (IBusAttribute *attr, - IBusMessageIter *iter) +static gint +ibus_attribute_deserialize (IBusAttribute *attr, + GVariant *variant) { - gboolean retval; - - retval = IBUS_SERIALIZABLE_CLASS (ibus_attribute_parent_class)->deserialize ((IBusSerializable *) attr, iter); - g_return_val_if_fail (retval, FALSE); + gint retval; - g_return_val_if_fail (IBUS_IS_ATTRIBUTE (attr), FALSE); + retval = IBUS_SERIALIZABLE_CLASS (ibus_attribute_parent_class)->deserialize ((IBusSerializable *) attr, variant); + g_return_val_if_fail (retval, 0); - retval = ibus_message_iter_get (iter, G_TYPE_UINT, &attr->type); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - - retval = ibus_message_iter_get (iter, G_TYPE_UINT, &attr->value); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); + g_variant_get_child (variant, retval++, "u", &attr->type); + g_variant_get_child (variant, retval++, "u", &attr->value); + g_variant_get_child (variant, retval++, "u", &attr->start_index); + g_variant_get_child (variant, retval++, "u", &attr->end_index); - retval = ibus_message_iter_get (iter, G_TYPE_UINT, &attr->start_index); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - - retval = ibus_message_iter_get (iter, G_TYPE_UINT, &attr->end_index); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - - return TRUE; + return retval; } diff --git a/src/ibusattribute.h b/src/ibusattribute.h index 51848ff..2628415 100644 --- a/src/ibusattribute.h +++ b/src/ibusattribute.h @@ -19,6 +19,11 @@ * 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: ibusattribute * @short_description: Attributes of IBusText. diff --git a/src/ibusattrlist.c b/src/ibusattrlist.c index b96a995..03741c6 100644 --- a/src/ibusattrlist.c +++ b/src/ibusattrlist.c @@ -19,33 +19,30 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include "ibusattrlist.h" /* functions prototype */ static void ibus_attr_list_destroy (IBusAttrList *attr_list); static gboolean ibus_attr_list_serialize (IBusAttrList *attr_list, - IBusMessageIter *iter); -static gboolean ibus_attr_list_deserialize (IBusAttrList *attr_list, - IBusMessageIter *iter); + GVariantBuilder *builder); +static gint ibus_attr_list_deserialize (IBusAttrList *attr_list, + GVariant *variant); static gboolean ibus_attr_list_copy (IBusAttrList *dest, const IBusAttrList *src); G_DEFINE_TYPE (IBusAttrList, ibus_attr_list, IBUS_TYPE_SERIALIZABLE) static void -ibus_attr_list_class_init (IBusAttrListClass *klass) +ibus_attr_list_class_init (IBusAttrListClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); - IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); + IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class); object_class->destroy = (IBusObjectDestroyFunc) ibus_attr_list_destroy; serializable_class->serialize = (IBusSerializableSerializeFunc) ibus_attr_list_serialize; serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_attr_list_deserialize; serializable_class->copy = (IBusSerializableCopyFunc) ibus_attr_list_copy; - - g_string_append (serializable_class->signature, "av"); } static void @@ -77,66 +74,47 @@ ibus_attr_list_destroy (IBusAttrList *attr_list) static gboolean ibus_attr_list_serialize (IBusAttrList *attr_list, - IBusMessageIter *iter) + GVariantBuilder *builder) { - IBusMessageIter array_iter; gboolean retval; guint i; - retval = IBUS_SERIALIZABLE_CLASS (ibus_attr_list_parent_class)->serialize ((IBusSerializable *)attr_list, iter); + retval = IBUS_SERIALIZABLE_CLASS (ibus_attr_list_parent_class)->serialize ((IBusSerializable *)attr_list, builder); g_return_val_if_fail (retval, FALSE); g_return_val_if_fail (IBUS_IS_ATTR_LIST (attr_list), FALSE); - retval = ibus_message_iter_open_container (iter, - IBUS_TYPE_ARRAY, - "v", - &array_iter); - g_return_val_if_fail (retval, FALSE); + GVariantBuilder array; + g_variant_builder_init (&array, G_VARIANT_TYPE ("av")); for (i = 0;; i++) { IBusAttribute *attr; - attr = ibus_attr_list_get (attr_list, i); if (attr == NULL) break; - - retval = ibus_message_iter_append (&array_iter, IBUS_TYPE_ATTRIBUTE, &attr); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (&array, "v", ibus_serializable_serialize ((IBusSerializable *)attr)); } - - retval = ibus_message_iter_close_container (iter, &array_iter); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "av", &array); return TRUE; } -static gboolean +static gint ibus_attr_list_deserialize (IBusAttrList *attr_list, - IBusMessageIter *iter) + GVariant *variant) { - DBusMessageIter array_iter; - gboolean retval; - - retval = IBUS_SERIALIZABLE_CLASS (ibus_attr_list_parent_class)->deserialize ((IBusSerializable *)attr_list, iter); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_recurse (iter, IBUS_TYPE_ARRAY, &array_iter); - g_return_val_if_fail (retval, FALSE); - - while (ibus_message_iter_get_arg_type (&array_iter) != G_TYPE_INVALID) { - IBusAttribute *attr; - - retval = ibus_message_iter_get (&array_iter, IBUS_TYPE_ATTRIBUTE, &attr); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (&array_iter); - - ibus_attr_list_append (attr_list, attr); + gint retval = IBUS_SERIALIZABLE_CLASS (ibus_attr_list_parent_class)->deserialize ((IBusSerializable *)attr_list, variant); + g_return_val_if_fail (retval, 0); + + GVariantIter *iter = NULL; + g_variant_get_child (variant, retval++, "av", &iter); + GVariant *var; + while (g_variant_iter_loop (iter, "v", &var)) { + ibus_attr_list_append (attr_list, IBUS_ATTRIBUTE (ibus_serializable_deserialize (var))); } + g_variant_iter_free (iter); - ibus_message_iter_next (iter); - - return TRUE; + return retval; } diff --git a/src/ibusattrlist.h b/src/ibusattrlist.h index 4180242..bbdf4bd 100644 --- a/src/ibusattrlist.h +++ b/src/ibusattrlist.h @@ -19,6 +19,11 @@ * 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: ibusattrlist * @Title: IBusAttrList diff --git a/src/ibusbus.c b/src/ibusbus.c index ea5e0d6..6b0a72e 100644 --- a/src/ibusbus.c +++ b/src/ibusbus.c @@ -20,20 +20,23 @@ * Boston, MA 02111-1307, USA. */ +#include "ibusbus.h" #include #include #include #include #include -#include -#include "ibusbus.h" +#include "ibusmarshalers.h" #include "ibusinternal.h" #include "ibusshare.h" -#include "ibusconnection.h" #include "ibusenginedesc.h" #include "ibusserializable.h" #include "ibusconfig.h" +#define DBUS_PATH_DBUS "/org/freedesktop/DBus" +#define DBUS_SERVICE_DBUS "org.freedesktop.DBus" +#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus" + #define IBUS_BUS_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_BUS, IBusBusPrivate)) @@ -48,45 +51,38 @@ enum { /* IBusBusPriv */ struct _IBusBusPrivate { GFileMonitor *monitor; - IBusConnection *connection; + GDBusConnection *connection; gboolean watch_dbus_signal; IBusConfig *config; gchar *unique_name; }; -typedef struct _IBusBusPrivate IBusBusPrivate; static guint bus_signals[LAST_SIGNAL] = { 0 }; static IBusBus *_bus = NULL; /* functions prototype */ -static GObject* ibus_bus_constructor (GType type, - guint n_params, - GObjectConstructParam - *params); -static void ibus_bus_destroy (IBusObject *object); -static void ibus_bus_watch_dbus_signal - (IBusBus *bus); -static void ibus_bus_unwatch_dbus_signal - (IBusBus *bus); +static GObject *ibus_bus_constructor (GType type, + guint n_params, + GObjectConstructParam *params); +static void ibus_bus_destroy (IBusObject *object); +static void ibus_bus_watch_dbus_signal (IBusBus *bus); +static void ibus_bus_unwatch_dbus_signal (IBusBus *bus); +static GVariant *ibus_bus_call (IBusBus *bus, + const gchar *service, + const gchar *path, + const gchar *interface, + const gchar *member, + GVariant *parameters, + const GVariantType *reply_type); G_DEFINE_TYPE (IBusBus, ibus_bus, IBUS_TYPE_OBJECT) -IBusBus * -ibus_bus_new (void) -{ - IBusBus *bus = IBUS_BUS (g_object_new (IBUS_TYPE_BUS, NULL)); - - return bus; -} - static void -ibus_bus_class_init (IBusBusClass *klass) +ibus_bus_class_init (IBusBusClass *class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IBusBusPrivate)); + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (class); gobject_class->constructor = ibus_bus_constructor; ibus_object_class->destroy = ibus_bus_destroy; @@ -101,11 +97,11 @@ ibus_bus_class_init (IBusBusClass *klass) */ bus_signals[CONNECTED] = g_signal_new (I_("connected"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -118,11 +114,11 @@ ibus_bus_class_init (IBusBusClass *klass) */ bus_signals[DISCONNECTED] = g_signal_new (I_("disconnected"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -135,23 +131,22 @@ ibus_bus_class_init (IBusBusClass *klass) */ bus_signals[GLOBAL_ENGINE_CHANGED] = g_signal_new (I_("global-engine-changed"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); -} + g_type_class_add_private (class, sizeof (IBusBusPrivate)); +} +#if 0 static gboolean -_connection_ibus_signal_cb (IBusConnection *connection, +_connection_ibus_signal_cb (GDBusConnection *connection, IBusMessage *message, IBusBus *bus) { - IBusBusPrivate *priv; - priv = IBUS_BUS_GET_PRIVATE (bus); - if (ibus_message_is_signal (message, IBUS_INTERFACE_IBUS, "GlobalEngineChanged")) { g_signal_emit (bus, bus_signals[GLOBAL_ENGINE_CHANGED], 0); @@ -159,29 +154,32 @@ _connection_ibus_signal_cb (IBusConnection *connection, } return FALSE; } +#endif static void -_connection_destroy_cb (IBusConnection *connection, - IBusBus *bus) +_connection_closed_cb (GDBusConnection *connection, + gboolean remote_peer_vanished, + GError *error, + IBusBus *bus) { - g_assert (IBUS_IS_BUS (bus)); - g_assert (IBUS_IS_CONNECTION (connection)); - - IBusBusPrivate *priv; - priv = IBUS_BUS_GET_PRIVATE (bus); + if (error) { + g_warning ("%s", error->message); + } - g_assert (priv->connection == connection); - g_signal_handlers_disconnect_by_func (priv->connection, - G_CALLBACK (_connection_destroy_cb), + g_assert (bus->priv->connection == connection); + g_signal_handlers_disconnect_by_func (bus->priv->connection, + G_CALLBACK (_connection_closed_cb), bus); - g_signal_handlers_disconnect_by_func (priv->connection, +#if 0 + g_signal_handlers_disconnect_by_func (bus->priv->connection, G_CALLBACK (_connection_ibus_signal_cb), bus); - g_object_unref (priv->connection); - priv->connection = NULL; +#endif + g_object_unref (bus->priv->connection); + bus->priv->connection = NULL; - g_free (priv->unique_name); - priv->unique_name = NULL; + g_free (bus->priv->unique_name); + bus->priv->unique_name = NULL; g_signal_emit (bus, bus_signals[DISCONNECTED], 0); } @@ -199,18 +197,25 @@ ibus_bus_connect (IBusBus *bus) } if (ibus_get_address () != NULL) { - priv->connection = ibus_connection_open (ibus_get_address ()); + bus->priv->connection = + g_dbus_connection_new_for_address_sync (ibus_get_address (), + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | + G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION, + NULL, NULL, NULL); } - if (priv->connection) { + if (bus->priv->connection) { + /* FIXME */ ibus_bus_hello (bus); - g_signal_connect (priv->connection, - "destroy", - (GCallback) _connection_destroy_cb, + g_signal_connect (bus->priv->connection, + "closed", + (GCallback) _connection_closed_cb, bus); g_signal_emit (bus, bus_signals[CONNECTED], 0); + /* FIXME */ + #if 0 if (priv->watch_dbus_signal) { ibus_bus_watch_dbus_signal (bus); } @@ -226,6 +231,7 @@ ibus_bus_connect (IBusBus *bus) "ibus-signal", (GCallback) _connection_ibus_signal_cb, bus); + #endif } } @@ -254,13 +260,12 @@ ibus_bus_init (IBusBus *bus) gchar *path; GFile *file; - IBusBusPrivate *priv; - priv = IBUS_BUS_GET_PRIVATE (bus); + bus->priv = IBUS_BUS_GET_PRIVATE (bus); - priv->config = NULL; - priv->connection = NULL; - priv->watch_dbus_signal = FALSE; - priv->unique_name = NULL; + bus->priv->config = NULL; + bus->priv->connection = NULL; + bus->priv->watch_dbus_signal = FALSE; + bus->priv->unique_name = NULL; path = g_path_get_dirname (ibus_get_socket_path ()); @@ -277,9 +282,9 @@ ibus_bus_init (IBusBus *bus) ibus_bus_connect (bus); file = g_file_new_for_path (ibus_get_socket_path ()); - priv->monitor = g_file_monitor_file (file, 0, NULL, NULL); + bus->priv->monitor = g_file_monitor_file (file, 0, NULL, NULL); - g_signal_connect (priv->monitor, "changed", (GCallback) _changed_cb, bus); + g_signal_connect (bus->priv->monitor, "changed", (GCallback) _changed_cb, bus); g_object_unref (file); g_free (path); @@ -309,49 +314,51 @@ ibus_bus_constructor (GType type, static void ibus_bus_destroy (IBusObject *object) { - IBusBus *bus; - IBusBusPrivate *priv; - - bus = IBUS_BUS (object); - priv = IBUS_BUS_GET_PRIVATE (bus); - g_assert (_bus == (IBusBus *)object); + + IBusBus * bus = _bus; _bus = NULL; - if (priv->monitor) { - g_object_unref (priv->monitor); - priv->monitor = NULL; + if (bus->priv->monitor) { + g_object_unref (bus->priv->monitor); + bus->priv->monitor = NULL; } - if (priv->config) { - ibus_object_destroy ((IBusObject *) priv->config); - priv->config = NULL; + if (bus->priv->config) { + ibus_proxy_destroy ((IBusProxy *) bus->priv->config); + bus->priv->config = NULL; } - if (priv->connection) { - ibus_object_destroy ((IBusObject *) priv->connection); - priv->connection = NULL; + if (bus->priv->connection) { + /* FIXME should use async close function */ + g_dbus_connection_close_sync (bus->priv->connection, NULL, NULL); + bus->priv->connection = NULL; } - g_free (priv->unique_name); - priv->unique_name = NULL; + g_free (bus->priv->unique_name); + bus->priv->unique_name = NULL; IBUS_OBJECT_CLASS (ibus_bus_parent_class)->destroy (object); } +IBusBus * +ibus_bus_new (void) +{ + IBusBus *bus = IBUS_BUS (g_object_new (IBUS_TYPE_BUS, NULL)); + + return bus; +} + + gboolean ibus_bus_is_connected (IBusBus *bus) { - g_assert (IBUS_IS_BUS (bus)); - - IBusBusPrivate *priv; - priv = IBUS_BUS_GET_PRIVATE (bus); + g_return_val_if_fail (IBUS_IS_BUS (bus), FALSE); - if (priv->connection) { - return ibus_connection_is_connected (priv->connection); - } + if (bus->priv->connection == NULL || g_dbus_connection_is_closed (bus->priv->connection)) + return FALSE; - return FALSE; + return TRUE; } @@ -359,186 +366,54 @@ IBusInputContext * ibus_bus_create_input_context (IBusBus *bus, const gchar *client_name) { - g_assert (IBUS_IS_BUS (bus)); - g_assert (client_name != NULL); - + g_return_val_if_fail (IBUS_IS_BUS (bus), NULL); + g_return_val_if_fail (client_name != NULL, NULL); g_return_val_if_fail (ibus_bus_is_connected (bus), NULL); gchar *path; - DBusMessage *call = NULL; - DBusMessage *reply = NULL; - IBusError *error; IBusInputContext *context = NULL; - IBusBusPrivate *priv; - priv = IBUS_BUS_GET_PRIVATE (bus); - - call = ibus_message_new_method_call (IBUS_SERVICE_IBUS, - IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "CreateInputContext"); - ibus_message_append_args (call, - G_TYPE_STRING, &client_name, - G_TYPE_INVALID); - - reply = ibus_connection_send_with_reply_and_block (priv->connection, - call, - -1, - &error); - ibus_message_unref (call); - - 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_message_unref (reply); - ibus_error_free (error); - return NULL; - } - - if (!ibus_message_get_args (reply, - &error, - IBUS_TYPE_OBJECT_PATH, &path, - G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_message_unref (reply); - ibus_error_free (error); - - return NULL; + GVariant *result; + result = ibus_bus_call (bus, + IBUS_SERVICE_IBUS, + IBUS_PATH_IBUS, + IBUS_INTERFACE_IBUS, + "CreateInputContext", + g_variant_new ("(s)", client_name), + G_VARIANT_TYPE ("(o)")); + + if (result != NULL) { + GError *error = NULL; + g_variant_get (result, "(&o)", &path); + context = ibus_input_context_new (path, bus->priv->connection, NULL, &error); + g_variant_unref (result); + if (context == NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } } - context = ibus_input_context_new (path, priv->connection); - ibus_message_unref (reply); - return context; } -IBusMessage * -ibus_bus_call_with_reply_valist (IBusBus *bus, - const gchar *name, - const gchar *path, - const gchar *interface, - const gchar *member, - GType first_arg_type, - va_list va_args) -{ - g_assert (IBUS_IS_BUS (bus)); - g_assert (name != NULL); - g_assert (path != NULL); - g_assert (interface != NULL); - g_assert (member); - - IBusMessage *message, *reply; - IBusError *error; - IBusBusPrivate *priv; - - g_return_val_if_fail (ibus_bus_is_connected (bus), FALSE); - - priv = IBUS_BUS_GET_PRIVATE (bus); - - message = ibus_message_new_method_call (name, path, interface, member); - - ibus_message_append_args_valist (message, first_arg_type, va_args); - - 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; - } - - return reply; -} - -IBusMessage * -ibus_bus_call_with_reply (IBusBus *bus, - const gchar *name, - const gchar *path, - const gchar *interface, - const gchar *member, - GType first_arg_type, - ...) -{ - IBusMessage *reply; - va_list va_args; - - va_start (va_args, first_arg_type); - reply = ibus_bus_call_with_reply_valist ( - bus, name, path, interface, member, first_arg_type, va_args); - va_end (va_args); - - return reply; -} - -gboolean -ibus_bus_call (IBusBus *bus, - const gchar *name, - const gchar *path, - const gchar *interface, - const gchar *member, - GType first_arg_type, - ...) -{ - IBusMessage *reply; - va_list va_args; - - va_start (va_args, first_arg_type); - reply = ibus_bus_call_with_reply_valist ( - bus, name, path, interface, member, first_arg_type, va_args); - va_end (va_args); - - if (reply) { - ibus_message_unref (reply); - return TRUE; - } - - return FALSE; -} - gchar * -ibus_bus_current_input_context(IBusBus *bus) +ibus_bus_current_input_context (IBusBus *bus) { - g_assert (IBUS_IS_BUS (bus)); + g_return_val_if_fail (IBUS_IS_BUS (bus), NULL); g_return_val_if_fail (ibus_bus_is_connected (bus), NULL); gchar *path = NULL; - IBusMessage *reply = NULL; - IBusError *error = NULL; - - reply = ibus_bus_call_with_reply (bus, - IBUS_SERVICE_IBUS, - IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "CurrentInputContext", - G_TYPE_INVALID); - - if (reply) { - if (ibus_message_get_args (reply, &error, - IBUS_TYPE_OBJECT_PATH, &path, - G_TYPE_INVALID)) { - path = g_strdup (path); - } else { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } + GVariant *result; + result = ibus_bus_call (bus, + IBUS_SERVICE_IBUS, + IBUS_PATH_IBUS, + IBUS_INTERFACE_IBUS, + "CurrentInputContext", + NULL, + G_VARIANT_TYPE ("(o)")); - ibus_message_unref (reply); + if (result != NULL) { + g_variant_get (result, "(o)", &path); + g_variant_unref (result); } return path; @@ -547,8 +422,6 @@ ibus_bus_current_input_context(IBusBus *bus) static void ibus_bus_watch_dbus_signal (IBusBus *bus) { - g_assert (IBUS_IS_BUS (bus)); - const gchar *rule; rule = "type='signal'," \ @@ -562,8 +435,6 @@ ibus_bus_watch_dbus_signal (IBusBus *bus) static void ibus_bus_unwatch_dbus_signal (IBusBus *bus) { - g_assert (IBUS_IS_BUS (bus)); - const gchar *rule; rule = "type='signal'," \ @@ -577,15 +448,12 @@ void ibus_bus_set_watch_dbus_signal (IBusBus *bus, gboolean watch) { - g_assert (IBUS_IS_BUS (bus)); - - IBusBusPrivate *priv; - priv = IBUS_BUS_GET_PRIVATE (bus); + g_return_if_fail (IBUS_IS_BUS (bus)); - if (priv->watch_dbus_signal == watch) + if (bus->priv->watch_dbus_signal == watch) return; - priv->watch_dbus_signal = watch; + bus->priv->watch_dbus_signal = watch; if (ibus_bus_is_connected (bus)) { if (watch) { @@ -600,38 +468,35 @@ ibus_bus_set_watch_dbus_signal (IBusBus *bus, const gchar * ibus_bus_hello (IBusBus *bus) { + g_return_val_if_fail (IBUS_IS_BUS (bus), NULL); + /* FIXME */ +#if 1 + if (bus->priv->connection) + return g_dbus_connection_get_unique_name (bus->priv->connection); + return NULL; +#else g_assert (IBUS_IS_BUS (bus)); - gchar *unique_name = NULL; - IBusMessage *reply = NULL; - IBusError *error = NULL; - IBusBusPrivate *priv; + GVariant *result; - priv = IBUS_BUS_GET_PRIVATE (bus); + g_free (bus->priv->unique_name); + bus->priv->unique_name = NULL; - g_free (priv->unique_name); - priv->unique_name = NULL; - - reply = ibus_bus_call_with_reply (bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "Hello", - G_TYPE_INVALID); - - if (reply) { - if (ibus_message_get_args (reply, &error, G_TYPE_STRING, &unique_name, - G_TYPE_INVALID)) { - priv->unique_name = g_strdup (unique_name); - } else { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } + result = ibus_bus_call (bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "Hello", + NULL, + G_VARIANT_TYPE ("(s)")); - ibus_message_unref (reply); + if (result) { + g_variant_get (result, "(s)", &bus->priv->unique_name); + g_variant_unref (result); } - return priv->unique_name; + return bus->priv->unique_name; +#endif } guint @@ -639,29 +504,22 @@ ibus_bus_request_name (IBusBus *bus, const gchar *name, guint flags) { - g_assert (IBUS_IS_BUS (bus)); + g_return_val_if_fail (IBUS_IS_BUS (bus), 0); + g_return_val_if_fail (name != NULL, 0); - IBusMessage *reply = NULL; - IBusError *error = NULL; guint retval = 0; + GVariant *result; + result = ibus_bus_call (bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "RequestName", + g_variant_new ("(su)", name, flags), + G_VARIANT_TYPE ("(u)")); - reply = ibus_bus_call_with_reply (bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "RequestName", - G_TYPE_STRING, &name, - G_TYPE_UINT, &flags, - G_TYPE_INVALID); - - if (reply) { - if (!ibus_message_get_args (reply, &error, G_TYPE_UINT, &retval, - G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } - - ibus_message_unref (reply); + if (result) { + g_variant_get (result, "(u)", &retval); + g_variant_unref (result); } return retval; @@ -671,28 +529,22 @@ guint ibus_bus_release_name (IBusBus *bus, const gchar *name) { - g_assert (IBUS_IS_BUS (bus)); + g_return_val_if_fail (IBUS_IS_BUS (bus), 0); + g_return_val_if_fail (name != NULL, 0); - IBusMessage *reply = NULL; - IBusError *error = NULL; guint retval = 0; + GVariant *result; + result = ibus_bus_call (bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "ReleaseName", + g_variant_new ("(s)", name), + G_VARIANT_TYPE ("(u)")); - reply = ibus_bus_call_with_reply (bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "ReleaseName", - G_TYPE_STRING, &name, - G_TYPE_INVALID); - - if (reply) { - if (!ibus_message_get_args (reply, &error, G_TYPE_UINT, &retval, - G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } - - ibus_message_unref (reply); + if (result) { + g_variant_get (result, "(u)", &retval); + g_variant_unref (result); } return retval; @@ -702,28 +554,22 @@ gboolean ibus_bus_name_has_owner (IBusBus *bus, const gchar *name) { - g_assert (IBUS_IS_BUS (bus)); + g_return_val_if_fail (IBUS_IS_BUS (bus), FALSE); + g_return_val_if_fail (name != NULL, FALSE); - IBusMessage *reply = NULL; - IBusError *error = NULL; gboolean retval = FALSE; + GVariant *result; + result = ibus_bus_call (bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "NameHasOwner", + g_variant_new ("(s)", name), + G_VARIANT_TYPE ("(b)")); - reply = ibus_bus_call_with_reply (bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "NameHasOwner", - G_TYPE_STRING, &name, - G_TYPE_INVALID); - - if (reply) { - if (!ibus_message_get_args (reply, &error, G_TYPE_BOOLEAN, &retval, - G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } - - ibus_message_unref (reply); + if (result) { + g_variant_get (result, "(b)", &retval); + g_variant_unref (result); } return retval; @@ -732,6 +578,7 @@ ibus_bus_name_has_owner (IBusBus *bus, GList * ibus_bus_list_names (IBusBus *bus) { + g_return_val_if_fail (IBUS_IS_BUS (bus), NULL); return NULL; } @@ -739,181 +586,145 @@ void ibus_bus_add_match (IBusBus *bus, const gchar *rule) { - g_assert (IBUS_IS_BUS (bus)); + g_return_if_fail (IBUS_IS_BUS (bus)); + g_return_if_fail (rule != NULL); + + GVariant *result; + result = ibus_bus_call (bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "AddMatch", + g_variant_new ("(s)", rule), + NULL); - ibus_bus_call (bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "AddMatch", - G_TYPE_STRING, &rule, - G_TYPE_INVALID); + if (result) { + g_variant_unref (result); + } } void ibus_bus_remove_match (IBusBus *bus, const gchar *rule) { - g_assert (IBUS_IS_BUS (bus)); + g_return_if_fail (IBUS_IS_BUS (bus)); + g_return_if_fail (rule != NULL); + + GVariant *result; + result = ibus_bus_call (bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "RemoveMatch", + g_variant_new ("(s)", rule), + NULL); - ibus_bus_call (bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "RemoveMatch", - G_TYPE_STRING, &rule, - G_TYPE_INVALID); + if (result) { + g_variant_unref (result); + } } gchar * ibus_bus_get_name_owner (IBusBus *bus, const gchar *name) { - g_assert (IBUS_IS_BUS (bus)); + g_return_val_if_fail (IBUS_IS_BUS (bus), NULL); - gchar *owner = NULL; - IBusMessage *reply = NULL; - IBusError *error = NULL; - - reply = ibus_bus_call_with_reply (bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "GetNameOwner", - G_TYPE_STRING, &name, - G_TYPE_INVALID); - - if (reply) { - if (ibus_message_get_args (reply, &error, G_TYPE_STRING, &owner, - G_TYPE_INVALID)) { - owner = g_strdup (owner); - } else { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } + gchar *retval = NULL; + GVariant *result; + result = ibus_bus_call (bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "GetNameOwner", + g_variant_new ("(s)", name), + G_VARIANT_TYPE ("(s)")); - ibus_message_unref (reply); + if (result) { + g_variant_get (result, "(s)", &retval); + g_variant_unref (result); } - return owner; + return retval; } -IBusConnection * +GDBusConnection * ibus_bus_get_connection (IBusBus *bus) { - g_assert (IBUS_IS_BUS (bus)); - - IBusBusPrivate *priv; - priv = IBUS_BUS_GET_PRIVATE (bus); + g_return_val_if_fail (IBUS_IS_BUS (bus), NULL); - return priv->connection; + return bus->priv->connection; } -gboolean +void ibus_bus_exit (IBusBus *bus, gboolean restart) { - g_assert (IBUS_IS_BUS (bus)); - - IBusBusPrivate *priv; - priv = IBUS_BUS_GET_PRIVATE (bus); + g_return_if_fail (IBUS_IS_BUS (bus)); - gboolean result; + GVariant *result; result = ibus_bus_call (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, "Exit", - G_TYPE_BOOLEAN, &restart, - G_TYPE_INVALID); - return result; + g_variant_new ("(b)", restart), + NULL); + + if (result) { + g_variant_unref (result); + } } gboolean ibus_bus_register_component (IBusBus *bus, IBusComponent *component) { - g_assert (IBUS_IS_BUS (bus)); - g_assert (IBUS_IS_COMPONENT (component)); - - gboolean result; - - result = ibus_bus_call (bus, - IBUS_SERVICE_IBUS, - IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "RegisterComponent", - IBUS_TYPE_COMPONENT, &component, - G_TYPE_INVALID); + g_return_val_if_fail (IBUS_IS_BUS (bus), FALSE); + g_return_val_if_fail (IBUS_IS_COMPONENT (component), FALSE); - return result; + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)component); + GVariant *result = ibus_bus_call (bus, + IBUS_SERVICE_IBUS, + IBUS_PATH_IBUS, + IBUS_INTERFACE_IBUS, + "RegisterComponent", + g_variant_new ("(v)", variant), + NULL); + if (result) { + g_variant_unref (result); + return FALSE; + } + return TRUE; } 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"; + g_return_val_if_fail (IBUS_IS_BUS (bus), NULL); - 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; + GList *retval = NULL; + GVariant *result; + result = ibus_bus_call (bus, + IBUS_SERVICE_IBUS, + IBUS_PATH_IBUS, + IBUS_INTERFACE_IBUS, + active_engines_only ? "ListActiveEngines" : "ListEngines", + NULL, + G_VARIANT_TYPE ("(av)")); + + if (result) { + GVariantIter *iter = NULL; + g_variant_get (result, "(av)", &iter); + GVariant *var; + while (g_variant_iter_loop (iter, "v", &var)) { + retval = g_list_append (retval, ibus_serializable_deserialize (var)); } - engines = g_list_append (engines, object); - ibus_message_iter_next (&subiter); - }; + g_variant_iter_free (iter); + g_variant_unref (result); + } - ibus_message_unref (reply); - return engines; + return retval; } GList * @@ -951,7 +762,7 @@ ibus_bus_get_config (IBusBus *bus) priv = IBUS_BUS_GET_PRIVATE (bus); if (priv->config == NULL && priv->connection) { - priv->config = ibus_config_new (priv->connection); + priv->config = ibus_config_new (priv->connection, NULL, NULL); if (priv->config) { g_signal_connect (priv->config, "destroy", G_CALLBACK (_config_destroy_cb), bus); } @@ -963,129 +774,152 @@ ibus_bus_get_config (IBusBus *bus) gboolean ibus_bus_get_use_sys_layout (IBusBus *bus) { - g_assert (IBUS_IS_BUS (bus)); - - IBusMessage *reply = NULL; - IBusError *error = NULL; - gboolean use_sys_layout = FALSE; + g_return_val_if_fail (IBUS_IS_BUS (bus), FALSE); - reply = ibus_bus_call_with_reply (bus, - IBUS_SERVICE_IBUS, - IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "GetUseSysLayout", - G_TYPE_INVALID); - if (reply) { - if (!ibus_message_get_args (reply, &error, G_TYPE_BOOLEAN, - &use_sys_layout, G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } + gboolean retval = FALSE; + GVariant *result; + result = ibus_bus_call (bus, + IBUS_SERVICE_IBUS, + IBUS_PATH_IBUS, + IBUS_INTERFACE_IBUS, + "GetUseSysLayout", + NULL, + G_VARIANT_TYPE ("(b)")); - ibus_message_unref (reply); + if (result) { + g_variant_get (result, "(b)", &retval); + g_variant_unref (result); } - return use_sys_layout; + return retval; } gboolean ibus_bus_get_use_global_engine (IBusBus *bus) { - g_assert (IBUS_IS_BUS (bus)); - - IBusMessage *reply = NULL; - IBusError *error = NULL; - gboolean use_global_engine = FALSE; + g_return_val_if_fail (IBUS_IS_BUS (bus), FALSE); - reply = ibus_bus_call_with_reply (bus, - IBUS_SERVICE_IBUS, - IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "GetUseGlobalEngine", - G_TYPE_INVALID); - if (reply) { - if (!ibus_message_get_args (reply, &error, G_TYPE_BOOLEAN, - &use_global_engine, G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } + gboolean retval = FALSE; + GVariant *result; + result = ibus_bus_call (bus, + IBUS_SERVICE_IBUS, + IBUS_PATH_IBUS, + IBUS_INTERFACE_IBUS, + "GetUseGlobalEngine", + NULL, + G_VARIANT_TYPE ("(b)")); - ibus_message_unref (reply); + if (result) { + g_variant_get (result, "(b)", &retval); + g_variant_unref (result); } - return use_global_engine; + return retval; } gboolean ibus_bus_is_global_engine_enabled (IBusBus *bus) { - g_assert (IBUS_IS_BUS (bus)); - - IBusMessage *reply = NULL; - IBusError *error = NULL; - gboolean global_engine_enabled = FALSE; + g_return_val_if_fail (IBUS_IS_BUS (bus), FALSE); - reply = ibus_bus_call_with_reply (bus, - IBUS_SERVICE_IBUS, - IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "IsGlobalEngineEnabled", - G_TYPE_INVALID); - if (reply) { - if (!ibus_message_get_args (reply, &error, G_TYPE_BOOLEAN, - &global_engine_enabled, G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } + gboolean retval = FALSE; + GVariant *result; + result = ibus_bus_call (bus, + IBUS_SERVICE_IBUS, + IBUS_PATH_IBUS, + IBUS_INTERFACE_IBUS, + "IsGlobalEngineEnabled", + NULL, + G_VARIANT_TYPE ("(b)")); - ibus_message_unref (reply); + if (result) { + g_variant_get (result, "(b)", &retval); + g_variant_unref (result); } - return global_engine_enabled; + return retval; } IBusEngineDesc * ibus_bus_get_global_engine (IBusBus *bus) { - g_assert (IBUS_IS_BUS (bus)); + g_return_val_if_fail (IBUS_IS_BUS (bus), NULL); - IBusMessage *reply = NULL; - IBusError *error = NULL; - IBusEngineDesc *global_engine = NULL; - - reply = ibus_bus_call_with_reply (bus, - IBUS_SERVICE_IBUS, - IBUS_PATH_IBUS, - IBUS_INTERFACE_IBUS, - "GetGlobalEngine", - G_TYPE_INVALID); - if (reply) { - if (!ibus_message_get_args (reply, &error, IBUS_TYPE_ENGINE_DESC, - &global_engine, G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } + GVariant *result; + IBusEngineDesc *engine = NULL; + result = ibus_bus_call (bus, + IBUS_SERVICE_IBUS, + IBUS_PATH_IBUS, + IBUS_INTERFACE_IBUS, + "GetGlobalEngine", + NULL, + G_VARIANT_TYPE ("(v)")); - ibus_message_unref (reply); + if (result) { + GVariant *variant = NULL; + g_variant_get (result, "(v)", &variant); + engine = IBUS_ENGINE_DESC (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + g_variant_unref (result); } - return global_engine; + return engine; } gboolean ibus_bus_set_global_engine (IBusBus *bus, const gchar *global_engine) { - g_assert (IBUS_IS_BUS (bus)); + g_return_val_if_fail (IBUS_IS_BUS (bus), FALSE); - gboolean result; + GVariant *result; result = ibus_bus_call (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, "SetGlobalEngine", - G_TYPE_STRING, &global_engine, - G_TYPE_INVALID); + g_variant_new ("(s)", global_engine), + NULL); + + if (result) { + g_variant_unref (result); + } + + return TRUE; +} + +static GVariant * +ibus_bus_call (IBusBus *bus, + const gchar *bus_name, + const gchar *path, + const gchar *interface, + const gchar *member, + GVariant *parameters, + const GVariantType *reply_type) +{ + g_assert (IBUS_IS_BUS (bus)); + g_assert (member != NULL); + g_return_val_if_fail (ibus_bus_is_connected (bus), NULL); + + GError *error = NULL; + GVariant *result; + result = g_dbus_connection_call_sync (bus->priv->connection, + bus_name, + path, + interface, + member, + parameters, + reply_type, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + if (result == NULL) { + g_warning ("%s.%s: %s", interface, member, error->message); + g_error_free (error); + return NULL; + } return result; } diff --git a/src/ibusbus.h b/src/ibusbus.h index 1d09c30..2e288f5 100644 --- a/src/ibusbus.h +++ b/src/ibusbus.h @@ -19,6 +19,11 @@ * 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: ibusbus * @short_description: Connect with IBus daemon. @@ -29,6 +34,7 @@ #ifndef __IBUS_BUS_H_ #define __IBUS_BUS_H_ +#include #include "ibusinputcontext.h" #include "ibusconfig.h" #include "ibuscomponent.h" @@ -55,6 +61,7 @@ G_BEGIN_DECLS typedef struct _IBusBus IBusBus; typedef struct _IBusBusClass IBusBusClass; +typedef struct _IBusBusPrivate IBusBusPrivate; /** * IBusBus: @@ -64,6 +71,8 @@ typedef struct _IBusBusClass IBusBusClass; struct _IBusBus { IBusObject parent; /* instance members */ + + IBusBusPrivate *priv; }; struct _IBusBusClass { @@ -94,9 +103,9 @@ gboolean ibus_bus_is_connected (IBusBus *bus); * @bus: An IBusBus. * @returns: TRUE if @bus is connected, FALSE otherwise. * - * Return IBusConnection of an IBusIBus instance. + * Return GDBusConnection of an IBusIBus instance. */ -IBusConnection +GDBusConnection *ibus_bus_get_connection (IBusBus *bus); /** @@ -190,11 +199,10 @@ gchar *ibus_bus_get_name_owner (IBusBus *bus, * ibus_bus_exit: * @bus: An IBusBus. * @restart: Whether restarting the ibus. - * @returns: TRUE if the "Exit" call is suceeded, FALSE otherwise. * * Exit or restart an IBusBus. */ -gboolean ibus_bus_exit (IBusBus *bus, +void ibus_bus_exit (IBusBus *bus, gboolean restart); /** diff --git a/src/ibuscomponent.c b/src/ibuscomponent.c index f09d2d9..47a0276 100644 --- a/src/ibuscomponent.c +++ b/src/ibuscomponent.c @@ -19,7 +19,6 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include #include "ibuscomponent.h" @@ -35,7 +34,6 @@ struct _IBusComponentPrivate { // TRUE if the component needs to be restarted when it dies. gboolean restart; }; -typedef struct _IBusComponentPrivate IBusComponentPrivate; #define IBUS_COMPONENT_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_COMPONENT, IBusComponentPrivate)) @@ -45,9 +43,9 @@ typedef struct _IBusComponentPrivate IBusComponentPrivate; /* functions prototype */ static void ibus_component_destroy (IBusComponent *component); static gboolean ibus_component_serialize (IBusComponent *component, - IBusMessageIter *iter); -static gboolean ibus_component_deserialize (IBusComponent *component, - IBusMessageIter *iter); + GVariantBuilder *builder); +static gint ibus_component_deserialize (IBusComponent *component, + GVariant *variant); static gboolean ibus_component_copy (IBusComponent *dest, const IBusComponent *src); static gboolean ibus_component_parse_xml_node @@ -65,42 +63,27 @@ static void ibus_component_parse_observed_paths G_DEFINE_TYPE (IBusComponent, ibus_component, IBUS_TYPE_SERIALIZABLE) static void -ibus_component_class_init (IBusComponentClass *klass) +ibus_component_class_init (IBusComponentClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); - IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); + IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class); - g_type_class_add_private (klass, sizeof (IBusComponentPrivate)); + g_type_class_add_private (class, sizeof (IBusComponentPrivate)); object_class->destroy = (IBusObjectDestroyFunc) ibus_component_destroy; serializable_class->serialize = (IBusSerializableSerializeFunc) ibus_component_serialize; serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_component_deserialize; serializable_class->copy = (IBusSerializableCopyFunc) ibus_component_copy; - - g_string_append (serializable_class->signature, "ssssssssavav"); } static void ibus_component_init (IBusComponent *component) { - component->name = NULL; - component->description = NULL; - component->version = NULL; - component->license = NULL; - component->author = NULL; - component->homepage = NULL; - component->exec = NULL; - component->textdomain = NULL; - component->engines = NULL; - component->observed_paths = NULL; - component->pid = 0; - component->child_source_id = 0; - - IBusComponentPrivate * priv = IBUS_COMPONENT_GET_PRIVATE (component); - priv->verbose = FALSE; - priv->restart = FALSE; + component->priv = IBUS_COMPONENT_GET_PRIVATE (component); + component->priv->verbose = FALSE; + component->priv->restart = FALSE; } static void @@ -154,144 +137,76 @@ ibus_component_destroy (IBusComponent *component) static gboolean ibus_component_serialize (IBusComponent *component, - IBusMessageIter *iter) + GVariantBuilder *builder) { gboolean retval; - IBusMessageIter array_iter; - GList *p; - - retval = IBUS_SERIALIZABLE_CLASS (ibus_component_parent_class)->serialize ((IBusSerializable *)component, iter); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &component->name); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &component->description); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &component->version); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &component->license); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &component->author); - g_return_val_if_fail (retval, FALSE); - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &component->homepage); + retval = IBUS_SERIALIZABLE_CLASS (ibus_component_parent_class)->serialize ((IBusSerializable *)component, builder); g_return_val_if_fail (retval, FALSE); - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &component->exec); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &component->textdomain); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "s", component->name); + g_variant_builder_add (builder, "s", component->description); + g_variant_builder_add (builder, "s", component->version); + g_variant_builder_add (builder, "s", component->license); + g_variant_builder_add (builder, "s", component->author); + g_variant_builder_add (builder, "s", component->homepage); + g_variant_builder_add (builder, "s", component->exec); + g_variant_builder_add (builder, "s", component->textdomain); + GList *p; + GVariantBuilder *array; /* serialize observed paths */ - retval = ibus_message_iter_open_container (iter, IBUS_TYPE_ARRAY, "v", &array_iter); - g_return_val_if_fail (retval, FALSE); - + array = g_variant_builder_new (G_VARIANT_TYPE ("av")); for (p = component->observed_paths; p != NULL; p = p->next) { - retval = ibus_message_iter_append (&array_iter, IBUS_TYPE_OBSERVED_PATH, &(p->data)); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (array, "v", ibus_serializable_serialize ((IBusSerializable *)p->data)); } - retval = ibus_message_iter_close_container (iter, &array_iter); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "av", array); /* serialize engine desc */ - retval = ibus_message_iter_open_container (iter, IBUS_TYPE_ARRAY, "v", &array_iter); - g_return_val_if_fail (retval, FALSE); - + array = g_variant_builder_new (G_VARIANT_TYPE ("av")); for (p = component->engines; p != NULL; p = p->next) { - retval = ibus_message_iter_append (&array_iter, IBUS_TYPE_ENGINE_DESC, &(p->data)); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (array, "v", ibus_serializable_serialize ((IBusSerializable *)p->data)); } - retval = ibus_message_iter_close_container (iter, &array_iter); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "av", array); return TRUE; } -static gboolean +static gint ibus_component_deserialize (IBusComponent *component, - IBusMessageIter *iter) + GVariant *variant) { gboolean retval; - gchar *str; - IBusMessageIter array_iter; - - retval = IBUS_SERIALIZABLE_CLASS (ibus_component_parent_class)->deserialize ((IBusSerializable *)component, iter); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - component->name = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - component->description = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - component->version = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - component->license = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - component->author = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - component->homepage = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - component->exec = g_strdup (str); - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - component->textdomain = g_strdup (str); - - retval = ibus_message_iter_recurse (iter, IBUS_TYPE_ARRAY, &array_iter); - g_return_val_if_fail (retval, FALSE); - while (ibus_message_iter_get_arg_type (&array_iter) != G_TYPE_INVALID) { - IBusObservedPath *path; - - retval = ibus_message_iter_get (&array_iter, IBUS_TYPE_OBSERVED_PATH, &path); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (&array_iter); - - g_object_ref_sink (path); - component->observed_paths = g_list_append (component->observed_paths, path); + retval = IBUS_SERIALIZABLE_CLASS (ibus_component_parent_class)->deserialize ((IBusSerializable *)component, variant); + g_return_val_if_fail (retval, 0); + + g_variant_get_child (variant, retval++, "s", &component->name); + g_variant_get_child (variant, retval++, "s", &component->description); + g_variant_get_child (variant, retval++, "s", &component->version); + g_variant_get_child (variant, retval++, "s", &component->license); + g_variant_get_child (variant, retval++, "s", &component->author); + g_variant_get_child (variant, retval++, "s", &component->homepage); + g_variant_get_child (variant, retval++, "s", &component->exec); + g_variant_get_child (variant, retval++, "s", &component->textdomain); + + GVariant *var; + GVariantIter *iter = NULL; + g_variant_get_child (variant, retval++, "av", &iter); + while (g_variant_iter_loop (iter, "v", &var)) { + component->observed_paths = g_list_append (component->observed_paths, + IBUS_OBSERVED_PATH (ibus_serializable_deserialize (var))); } - ibus_message_iter_next (iter); + g_variant_iter_free (iter); - retval = ibus_message_iter_recurse (iter, IBUS_TYPE_ARRAY, &array_iter); - g_return_val_if_fail (retval, FALSE); - - while (ibus_message_iter_get_arg_type (&array_iter) != G_TYPE_INVALID) { - IBusEngineDesc *engine; - - retval = ibus_message_iter_get (&array_iter, IBUS_TYPE_ENGINE_DESC, &engine); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (&array_iter); - - ibus_component_add_engine (component, engine); + g_variant_get_child (variant, retval++, "av", &iter); + while (g_variant_iter_loop (iter, "v", &var)) { + component->engines = g_list_append (component->engines, + IBUS_ENGINE_DESC (ibus_serializable_deserialize (var))); } - ibus_message_iter_next (iter); + g_variant_iter_free (iter); - return TRUE; + return retval; } static gboolean @@ -772,7 +687,5 @@ void ibus_component_set_restart (IBusComponent *component, gboolean restart) { g_assert (IBUS_IS_COMPONENT (component)); - - IBusComponentPrivate *priv = IBUS_COMPONENT_GET_PRIVATE (component); - priv->restart = restart; + component->priv->restart = restart; } diff --git a/src/ibuscomponent.h b/src/ibuscomponent.h index fb5f0ce..8fb050d 100644 --- a/src/ibuscomponent.h +++ b/src/ibuscomponent.h @@ -19,6 +19,11 @@ * 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: ibuscomponent * @short_description: Component (executable) specification. @@ -66,6 +71,7 @@ G_BEGIN_DECLS typedef struct _IBusComponent IBusComponent; typedef struct _IBusComponentClass IBusComponentClass; +typedef struct _IBusComponentPrivate IBusComponentPrivate; /** * IBusComponent: @@ -81,7 +87,9 @@ typedef struct _IBusComponentClass IBusComponentClass; * An IBusComponent stores component information. */ struct _IBusComponent { + /*< private >*/ IBusSerializable parent; + IBusComponentPrivate *priv; /* instance members */ /*< public >*/ diff --git a/src/ibusconfig.c b/src/ibusconfig.c index 6278d85..3db4bc1 100644 --- a/src/ibusconfig.c +++ b/src/ibusconfig.c @@ -19,7 +19,6 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include "ibusinternal.h" #include "ibusmarshalers.h" #include "ibusshare.h" @@ -59,71 +58,28 @@ static BusPair *bus_pair_new (GType car_type static BusPair *bus_pair_copy (BusPair *pair); static void bus_pair_free (BusPair *pair); #endif -static void ibus_config_class_init (IBusConfigClass *klass); -static void ibus_config_init (IBusConfig *config); -static void ibus_config_real_destroy (IBusConfig *config); +static void ibus_config_class_init (IBusConfigClass *class); +static void ibus_config_init (IBusConfig *config); +static void ibus_config_real_destroy (IBusProxy *proxy); -static gboolean ibus_config_ibus_signal (IBusProxy *proxy, - IBusMessage *message); +static void ibus_config_g_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters); -static IBusProxyClass *parent_class = NULL; - -GType -ibus_config_get_type (void) -{ - static GType type = 0; - - static const GTypeInfo type_info = { - sizeof (IBusConfigClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) ibus_config_class_init, - NULL, /* class finalize */ - NULL, /* class data */ - sizeof (IBusConfig), - 0, - (GInstanceInitFunc) ibus_config_init, - }; - - if (type == 0) { - type = g_type_register_static (IBUS_TYPE_PROXY, - "IBusConfig", - &type_info, - (GTypeFlags)0); - } - return type; -} - -IBusConfig * -ibus_config_new (IBusConnection *connection) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - - GObject *obj; - obj = g_object_new (IBUS_TYPE_CONFIG, - "name", IBUS_SERVICE_CONFIG, - "interface", IBUS_INTERFACE_CONFIG, - "path", IBUS_PATH_CONFIG, - "connection", connection, - NULL); - - return IBUS_CONFIG (obj); -} +G_DEFINE_TYPE (IBusConfig, ibus_config, IBUS_TYPE_PROXY) static void -ibus_config_class_init (IBusConfigClass *klass) +ibus_config_class_init (IBusConfigClass *class) { - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - IBusProxyClass *proxy_class = IBUS_PROXY_CLASS (klass); + GDBusProxyClass *dbus_proxy_class = G_DBUS_PROXY_CLASS (class); + IBusProxyClass *proxy_class = IBUS_PROXY_CLASS (class); + g_type_class_add_private (class, sizeof (IBusConfigPrivate)); - parent_class = (IBusProxyClass *) g_type_class_peek_parent (klass); + dbus_proxy_class->g_signal = ibus_config_g_signal; + proxy_class->destroy = ibus_config_real_destroy; - g_type_class_add_private (klass, sizeof (IBusConfigPrivate)); - - ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_config_real_destroy; - - proxy_class->ibus_signal = ibus_config_ibus_signal; /* install signals */ /** @@ -138,16 +94,16 @@ ibus_config_class_init (IBusConfigClass *klass) */ config_signals[VALUE_CHANGED] = g_signal_new (I_("value-changed"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__STRING_STRING_BOXED, + _ibus_marshal_VOID__STRING_STRING_VARIANT, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_VALUE | G_SIGNAL_TYPE_STATIC_SCOPE); + G_TYPE_VARIANT | G_SIGNAL_TYPE_STATIC_SCOPE); } static void @@ -158,130 +114,122 @@ ibus_config_init (IBusConfig *config) } static void -ibus_config_real_destroy (IBusConfig *config) +ibus_config_real_destroy (IBusProxy *proxy) { - if (ibus_proxy_get_connection ((IBusProxy *) config) != NULL) { - ibus_proxy_call ((IBusProxy *) config, - "Destroy", - G_TYPE_INVALID); - } - - IBUS_OBJECT_CLASS(parent_class)->destroy (IBUS_OBJECT (config)); + IBUS_PROXY_CLASS(ibus_config_parent_class)->destroy (proxy); } -static gboolean -ibus_config_ibus_signal (IBusProxy *proxy, - IBusMessage *message) +static void +ibus_config_g_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters) { - g_assert (IBUS_IS_CONFIG (proxy)); - g_assert (message != NULL); - - IBusConfig *config; - config = IBUS_CONFIG (proxy); - - if (ibus_message_is_signal (message, IBUS_INTERFACE_CONFIG, "ValueChanged")) { + if (g_strcmp0 (signal_name,"ValueChanged")) { gchar *section; gchar *name; - GValue value = { 0 }; - IBusError *error = NULL; - gboolean retval; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, §ion, - G_TYPE_STRING, &name, - G_TYPE_VALUE, &value, - G_TYPE_INVALID); - if (!retval) { - g_warning ("%s: Can not parse arguments of ValueChanges.", DBUS_ERROR_INVALID_ARGS); - return FALSE; - } - - g_signal_emit (config, + GVariant *value; + + g_variant_get (parameters, "(&s&sv)", §ion, &name, &value); + + g_signal_emit (proxy, config_signals[VALUE_CHANGED], 0, section, name, - &value); - g_value_unset (&value); - - g_signal_stop_emission_by_name (config, "ibus-signal"); - - return TRUE; + value); + return; } - return FALSE; + G_DBUS_PROXY_CLASS (ibus_config_parent_class)->g_signal (proxy, sender_name, signal_name, parameters); } -gboolean +IBusConfig * +ibus_config_new (GDBusConnection *connection, + GCancellable *cancellable, + GError **error) +{ + g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); + + GInitable *initable; + + initable = g_initable_new (IBUS_TYPE_CONFIG, + cancellable, + error, + "g-connection", connection, + "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + "g-name", IBUS_SERVICE_CONFIG, + "g-interface-name", IBUS_INTERFACE_CONFIG, + "g-object-path", IBUS_PATH_CONFIG, + NULL); + if (initable != NULL) + return IBUS_CONFIG (initable); + return NULL; +} + +GVariant * ibus_config_get_value (IBusConfig *config, const gchar *section, - const gchar *name, - GValue *value) + const gchar *name) { - g_assert (IBUS_IS_CONFIG (config)); - g_assert (section != NULL); - g_assert (name != NULL); - g_assert (value != NULL); - - IBusMessage *reply; - IBusError *error; - gboolean retval; - - reply = ibus_proxy_call_with_reply_and_block ((IBusProxy *) config, - "GetValue", - -1, - &error, - G_TYPE_STRING, §ion, - G_TYPE_STRING, &name, - G_TYPE_INVALID); - if (reply == NULL) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - return FALSE; - } - - 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 FALSE; + g_return_val_if_fail (IBUS_IS_CONFIG (config), NULL); + g_return_val_if_fail (section != NULL, NULL); + g_return_val_if_fail (name != NULL, NULL); + + GError *error = NULL; + GVariant *result; + result = g_dbus_proxy_call_sync ((GDBusProxy *) config, + "GetValue", /* method_name */ + g_variant_new ("(ss)", + section, name), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + &error /* error */ + ); + if (result == NULL) { + g_warning ("%s.GetValue: %s", IBUS_INTERFACE_CONFIG, error->message); + g_error_free (error); + return NULL; } - retval = ibus_message_get_args (reply, - &error, - G_TYPE_VALUE, value, - G_TYPE_INVALID); - ibus_message_unref (reply); - if (!retval) { - g_warning ("%s: %s", error->name, error->message); - return FALSE; - } + GVariant *value; + g_variant_get (result, "(v)", &value); + g_variant_ref (value); + g_variant_unref (result); - return TRUE; + return value; } gboolean ibus_config_set_value (IBusConfig *config, const gchar *section, const gchar *name, - const GValue *value) + GVariant *value) { - g_assert (IBUS_IS_CONFIG (config)); - g_assert (section != NULL); - g_assert (name != NULL); - g_assert (value != NULL); - - gboolean retval; - - retval = ibus_proxy_call ((IBusProxy *) config, - "SetValue", - G_TYPE_STRING, §ion, - G_TYPE_STRING, &name, - G_TYPE_VALUE, value, - G_TYPE_INVALID); - g_assert (retval); + g_return_val_if_fail (IBUS_IS_CONFIG (config), FALSE); + g_return_val_if_fail (section != NULL, FALSE); + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (value != NULL, FALSE); + + GError *error = NULL; + GVariant *result; + result = g_dbus_proxy_call_sync ((GDBusProxy *) config, + "SetValue", /* method_name */ + g_variant_new ("(ssv)", + section, name, value), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + &error /* error */ + ); + if (result == NULL) { + g_warning ("%s.SetValue: %s", IBUS_INTERFACE_CONFIG, error->message); + g_error_free (error); + return FALSE; + } + g_variant_unref (result); return TRUE; } @@ -290,17 +238,26 @@ ibus_config_unset (IBusConfig *config, const gchar *section, const gchar *name) { - g_assert (IBUS_IS_CONFIG (config)); - g_assert (section != NULL); - g_assert (name != NULL); - - gboolean retval; - - retval = ibus_proxy_call ((IBusProxy *) config, - "Unset", - G_TYPE_STRING, §ion, - G_TYPE_STRING, &name, - G_TYPE_INVALID); - g_assert (retval); + g_return_val_if_fail (IBUS_IS_CONFIG (config), FALSE); + g_return_val_if_fail (section != NULL, FALSE); + g_return_val_if_fail (name != NULL, FALSE); + + GError *error = NULL; + GVariant *result; + result = g_dbus_proxy_call_sync ((GDBusProxy *) config, + "UnsetValue", /* method_name */ + g_variant_new ("(ss)", + section, name), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + &error /* error */ + ); + if (result == NULL) { + g_warning ("%s.UnsetValue: %s", IBUS_INTERFACE_CONFIG, error->message); + g_error_free (error); + return FALSE; + } + g_variant_unref (result); return TRUE; } diff --git a/src/ibusconfig.h b/src/ibusconfig.h index b137cdb..010d0c5 100644 --- a/src/ibusconfig.h +++ b/src/ibusconfig.h @@ -19,6 +19,11 @@ * 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: ibusconfig * @title: IBusConfig @@ -76,20 +81,21 @@ GType ibus_config_get_type (void); /** * ibus_config_new: - * @connection: An IBusConnection. + * @connection: An GDBusConnection. * @returns: An newly allocated IBusConfig corresponding to @connection. * - * New a IBusConfig from existing IBusConnection. + * New a IBusConfig from existing GDBusConnection. */ -IBusConfig *ibus_config_new (IBusConnection *connection); +IBusConfig *ibus_config_new (GDBusConnection *connection, + GCancellable *cancellable, + GError **error); /** * ibus_config_get_value: * @config: An IBusConfig * @section: Section name of the configuration option. * @name: Name of the configure option. - * @value: GValue that holds the value. - * @returns: TRUE if succeed; FALSE otherwise. + * @returns: a GVariant. * * Get the value of a configuration option. * @@ -102,10 +108,9 @@ IBusConfig *ibus_config_new (IBusConnection *connection); * so the section name for it is "engine/Chewing". * @see_also: ibus_config_set_value. */ -gboolean ibus_config_get_value (IBusConfig *config, +GVariant *ibus_config_get_value (IBusConfig *config, const gchar *section, - const gchar *name, - GValue *value); + const gchar *name); /** * ibus_config_set_value: @@ -121,7 +126,7 @@ gboolean ibus_config_get_value (IBusConfig *config, gboolean ibus_config_set_value (IBusConfig *config, const gchar *section, const gchar *name, - const GValue *value); + GVariant *value); /** * ibus_config_unset: diff --git a/src/ibusconfigprivate.h b/src/ibusconfigprivate.h index 478f4ab..30efe91 100644 --- a/src/ibusconfigprivate.h +++ b/src/ibusconfigprivate.h @@ -19,6 +19,11 @@ * 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 + #ifndef __IBUS_CONFIG_PRIVATE_H_ #define __IBUS_CONFIG_PRIVATE_H_ diff --git a/src/ibusconfigservice.c b/src/ibusconfigservice.c index b0658a9..e237f5a 100644 --- a/src/ibusconfigservice.c +++ b/src/ibusconfigservice.c @@ -19,130 +19,128 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include "ibusshare.h" #include "ibusconfigservice.h" +#define IBUS_CONFIG_SERVICE_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_CONFIG_SERVICE, IBusConfigServicePrivate)) + enum { LAST_SIGNAL, }; enum { PROP_0, - PROP_CONNECTION, }; // static guint config_service_signals[LAST_SIGNAL] = { 0 }; /* functions prototype */ -static void ibus_config_service_class_init (IBusConfigServiceClass *klass); -static void ibus_config_service_init (IBusConfigService *config); -static void ibus_config_service_set_property (IBusConfigService *config, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void ibus_config_service_get_property (IBusConfigService *config, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void ibus_config_service_destroy (IBusConfigService *config); -static gboolean ibus_config_service_ibus_message (IBusConfigService *config, - IBusConnection *connection, - IBusMessage *message); -static gboolean ibus_config_service_set_value (IBusConfigService *config, - const gchar *section, - const gchar *name, - const GValue *value, - IBusError **error); -static gboolean ibus_config_service_get_value (IBusConfigService *config, - const gchar *section, - const gchar *name, - GValue *value, - IBusError **error); -static gboolean ibus_config_service_unset (IBusConfigService *config, - const gchar *section, - const gchar *name, - IBusError **error); - -static IBusServiceClass *parent_class = NULL; - -GType -ibus_config_service_get_type (void) -{ - static GType type = 0; - - static const GTypeInfo type_info = { - sizeof (IBusConfigServiceClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) ibus_config_service_class_init, - NULL, /* class finalize */ - NULL, /* class data */ - sizeof (IBusConfigService), - 0, - (GInstanceInitFunc) ibus_config_service_init, - }; - - if (type == 0) { - type = g_type_register_static (IBUS_TYPE_SERVICE, - "IBusConfigService", - &type_info, - (GTypeFlags) 0); - } - return type; -} - -IBusConfigService * -ibus_config_service_new (IBusConnection *connection) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - - IBusConfigService *config; - - config = (IBusConfigService *) g_object_new (IBUS_TYPE_CONFIG_SERVICE, - "path", IBUS_PATH_CONFIG, - "connection", connection, - NULL); - - return config; -} +static void ibus_config_service_class_init (IBusConfigServiceClass *class); +static void ibus_config_service_init (IBusConfigService *config); +static void ibus_config_service_set_property (IBusConfigService *config, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void ibus_config_service_get_property (IBusConfigService *config, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void ibus_config_service_destroy (IBusConfigService *config); +static void ibus_config_service_service_method_call + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation); +static GVariant *ibus_config_service_service_get_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error); +static gboolean ibus_config_service_service_set_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error); +static gboolean ibus_config_service_set_value (IBusConfigService *config, + const gchar *section, + const gchar *name, + GVariant *value, + GError **error); +static GVariant *ibus_config_service_get_value (IBusConfigService *config, + const gchar *section, + const gchar *name, + GError **error); +static gboolean ibus_config_service_unset_value (IBusConfigService *config, + const gchar *section, + const gchar *name, + GError **error); + +G_DEFINE_TYPE (IBusConfigService, ibus_config_service, IBUS_TYPE_SERVICE) + +static const gchar introspection_xml[] = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; static void -ibus_config_service_class_init (IBusConfigServiceClass *klass) +ibus_config_service_class_init (IBusConfigServiceClass *class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - parent_class = (IBusServiceClass *) g_type_class_peek_parent (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (class); gobject_class->set_property = (GObjectSetPropertyFunc) ibus_config_service_set_property; gobject_class->get_property = (GObjectGetPropertyFunc) ibus_config_service_get_property; IBUS_OBJECT_CLASS (gobject_class)->destroy = (IBusObjectDestroyFunc) ibus_config_service_destroy; - IBUS_SERVICE_CLASS (klass)->ibus_message = (ServiceIBusMessageFunc) ibus_config_service_ibus_message; + IBUS_SERVICE_CLASS (class)->service_method_call = ibus_config_service_service_method_call; + IBUS_SERVICE_CLASS (class)->service_get_property = ibus_config_service_service_get_property; + IBUS_SERVICE_CLASS (class)->service_set_property = ibus_config_service_service_set_property; + + ibus_service_class_add_interfaces (IBUS_SERVICE_CLASS (class), introspection_xml); - klass->set_value = ibus_config_service_set_value; - klass->get_value = ibus_config_service_get_value; - klass->unset = ibus_config_service_unset; + class->set_value = ibus_config_service_set_value; + class->get_value = ibus_config_service_get_value; + class->unset_value = ibus_config_service_unset_value; /* install properties */ - /** - * IBusConfigService:connection: - * - * Connection of this IBusConfigService. + /* + * g_type_class_add_private (class, sizeof (IBusConfigServicePrivate)); */ - g_object_class_install_property (gobject_class, - PROP_CONNECTION, - g_param_spec_object ("connection", - "connection", - "The connection of config object", - IBUS_TYPE_CONNECTION, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } static void ibus_config_service_init (IBusConfigService *config) { + /* + * config->priv = IBUS_CONFIG_SERVICE_GET_PRIVATE (config); + */ } static void @@ -152,11 +150,12 @@ ibus_config_service_set_property (IBusConfigService *config, GParamSpec *pspec) { switch (prop_id) { + #if 0 case PROP_CONNECTION: ibus_service_add_to_connection ((IBusService *) config, g_value_get_object (value)); break; - + #endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (config, prop_id, pspec); } @@ -169,18 +168,10 @@ ibus_config_service_get_property (IBusConfigService *config, GParamSpec *pspec) { switch (prop_id) { + #if 0 case PROP_CONNECTION: - { - GList *connections = ibus_service_get_connections ((IBusService *) config); - if (connections) { - g_value_set_object (value, connections->data); - } - else { - g_value_set_object (value, NULL); - } - g_list_free (connections); - } break; + #endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (config, prop_id, pspec); } @@ -189,182 +180,205 @@ ibus_config_service_get_property (IBusConfigService *config, static void ibus_config_service_destroy (IBusConfigService *config) { - IBUS_OBJECT_CLASS(parent_class)->destroy ((IBusObject *) config); + IBUS_OBJECT_CLASS(ibus_config_service_parent_class)->destroy ((IBusObject *) config); } -static gboolean -ibus_config_service_ibus_message (IBusConfigService *config, - IBusConnection *connection, - IBusMessage *message) +static void +ibus_config_service_service_method_call (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (IBUS_IS_CONFIG_SERVICE (config)); - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (message != NULL); - - IBusMessage *reply = NULL; + IBusConfigService *config = IBUS_CONFIG_SERVICE (service); + + if (g_strcmp0 (interface_name, IBUS_INTERFACE_CONFIG) != 0) { + IBUS_SERVICE_CLASS (ibus_config_service_parent_class)-> + service_method_call (service, + connection, + sender, + object_path, + interface_name, + method_name, + parameters, + invocation); + return; + } - if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "SetValue")) { + if (g_strcmp0 (method_name, "SetValue") == 0) { gchar *section; gchar *name; - GValue value = { 0 }; - IBusError *error = NULL; + GVariant *value; gboolean retval; + GError *error = NULL; + + g_variant_get (parameters, "(&s&sv)", §ion, &name, &value); - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, §ion, - G_TYPE_STRING, &name, - G_TYPE_VALUE, &value, - G_TYPE_INVALID); - if (!retval) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "Can not parse arguments 1 of SetValue"); - ibus_error_free (error); + retval = IBUS_CONFIG_SERVICE_GET_CLASS (config)->set_value (config, section, name, value, &error); + if (retval) { + g_dbus_method_invocation_return_value (invocation, NULL); } else { - if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->set_value (config, section, name, &value, &error)) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - } - else { - reply = ibus_message_new_method_return (message); - } - g_value_unset (&value); + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); } + return; } - else if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "GetValue")) { + + if (g_strcmp0 (method_name, "GetValue") == 0) { gchar *section; gchar *name; - GValue value = { 0 }; - IBusError *error = NULL; - gboolean retval; + GVariant *value; + GError *error = NULL; - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, §ion, - G_TYPE_STRING, &name, - G_TYPE_INVALID); - - if (!retval) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - } - else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->get_value (config, section, name, &value, &error)) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); + g_variant_get (parameters, "(&s&s)", §ion, &name); + + value = IBUS_CONFIG_SERVICE_GET_CLASS (config)->get_value (config, section, name, &error); + if (value != NULL) { + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", value)); } else { - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - G_TYPE_VALUE, &value, - G_TYPE_INVALID); - g_value_unset (&value); + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); } + return; } - else if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "Unset")) { + + if (g_strcmp0 (method_name, "UnsetValue") == 0) { gchar *section; gchar *name; - IBusError *error = NULL; gboolean retval; + GError *error = NULL; - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, §ion, - G_TYPE_STRING, &name, - G_TYPE_INVALID); - if (!retval) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "Can not parse arguments 1 of Unset"); - ibus_error_free (error); - } - else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->unset (config, section, name, &error)) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); + g_variant_get (parameters, "(&s&s)", §ion, &name); + + retval = IBUS_CONFIG_SERVICE_GET_CLASS (config)->unset_value (config, section, name, &error); + if (retval) { + g_dbus_method_invocation_return_value (invocation, NULL); } else { - reply = ibus_message_new_method_return (message); + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); } + return; } - if (reply) { - ibus_connection_send (connection, reply); - ibus_message_unref (reply); - return TRUE; - } + /* should not be reached */ + g_return_if_reached (); +} - return parent_class->ibus_message ((IBusService *) config, connection, message); +static GVariant * +ibus_config_service_service_get_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error) +{ + return IBUS_SERVICE_CLASS (ibus_config_service_parent_class)-> + service_get_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + error); +} + +static gboolean +ibus_config_service_service_set_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error) +{ + return IBUS_SERVICE_CLASS (ibus_config_service_parent_class)-> + service_set_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + value, + error); } static gboolean ibus_config_service_set_value (IBusConfigService *config, const gchar *section, const gchar *name, - const GValue *value, - IBusError **error) + GVariant *value, + GError **error) { if (error) { - *error = ibus_error_new_from_printf (DBUS_ERROR_FAILED, - "Can not set value [%s, %s]", - section, name); + gchar *str = g_variant_print (value, TRUE); + *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Cannot set value %s::%s to %s", section, name, str); + g_free (str); } return FALSE; } -static gboolean +static GVariant * ibus_config_service_get_value (IBusConfigService *config, const gchar *section, const gchar *name, - GValue *value, - IBusError **error) + GError **error) { if (error) { - *error = ibus_error_new_from_printf (DBUS_ERROR_FAILED, - "Can not get value [%s, %s]", - section, name); + *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Cannot get value %s::%s", section, name); } - return FALSE; + return NULL; } static gboolean -ibus_config_service_unset (IBusConfigService *config, - const gchar *section, - const gchar *name, - IBusError **error) +ibus_config_service_unset_value (IBusConfigService *config, + const gchar *section, + const gchar *name, + GError **error) { if (error) { - *error = ibus_error_new_from_printf (DBUS_ERROR_FAILED, - "Can not unset [%s, %s]", - section, name); + *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Cannot unset value %s::%s", section, name); } return FALSE; } +IBusConfigService * +ibus_config_service_new (GDBusConnection *connection) +{ + g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); + + GObject *object = g_object_new (IBUS_TYPE_CONFIG_SERVICE, + "object-path", IBUS_PATH_CONFIG, + "connection", connection, + NULL); + return IBUS_CONFIG_SERVICE (object); +} + void ibus_config_service_value_changed (IBusConfigService *config, const gchar *section, const gchar *name, - const GValue *value) + GVariant *value) { - g_assert (IBUS_IS_CONFIG_SERVICE (config)); - g_assert (section); - g_assert (name); - g_assert (G_IS_VALUE (value)); + g_return_if_fail (IBUS_IS_CONFIG_SERVICE (config)); + g_return_if_fail (section != NULL); + g_return_if_fail (name != NULL); + g_return_if_fail (value != NULL); - ibus_service_send_signal ((IBusService *) config, + ibus_service_emit_signal ((IBusService *) config, + NULL, IBUS_INTERFACE_CONFIG, "ValueChanged", - G_TYPE_STRING, §ion, - G_TYPE_STRING, &name, - G_TYPE_VALUE, value, - G_TYPE_INVALID); + g_variant_new ("(ssv)", section, name, value), + NULL); } diff --git a/src/ibusconfigservice.h b/src/ibusconfigservice.h index 5c4ccaa..2f83fa0 100644 --- a/src/ibusconfigservice.h +++ b/src/ibusconfigservice.h @@ -19,6 +19,11 @@ * 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: ibusconfigservice * @short_description: Configuration service back-end. @@ -129,7 +134,6 @@ #ifndef __IBUS_CONFIG_SERVICE_H_ #define __IBUS_CONFIG_SERVICE_H_ -#include "ibuserror.h" #include "ibusservice.h" /* @@ -161,28 +165,32 @@ typedef struct _IBusConfigServiceClass IBusConfigServiceClass; * An opaque data type representing a configure service. */ struct _IBusConfigService { + /*< private >*/ IBusService parent; + /* IBusConfigServicePriv *priv */ + /* instance members */ }; struct _IBusConfigServiceClass { + /*< private >*/ IBusServiceClass parent; + /*< public >*/ /* class members */ - gboolean (* set_value) (IBusConfigService *config, - const gchar *section, - const gchar *name, - const GValue *value, - IBusError **error); - gboolean (* get_value) (IBusConfigService *config, - const gchar *section, - const gchar *name, - GValue *value, - IBusError **error); - gboolean (* unset) (IBusConfigService *config, - const gchar *section, - const gchar *name, - IBusError **error); + gboolean (* set_value) (IBusConfigService *config, + const gchar *section, + const gchar *name, + GVariant *value, + GError **error); + GVariant * (* get_value) (IBusConfigService *config, + const gchar *section, + const gchar *name, + GError **error); + gboolean (* unset_value) (IBusConfigService *config, + const gchar *section, + const gchar *name, + GError **error); /*< private >*/ /* padding */ @@ -193,19 +201,19 @@ GType ibus_config_service_get_type (void); /** * ibus_config_service_new: - * @connection: An IBusConnection. + * @connection: An GDBusConnection. * @returns: A newly allocated IBusConfigServices. * - * New an IBusConfigService from an IBusConnection. + * New an IBusConfigService from an GDBusConnection. */ -IBusConfigService *ibus_config_service_new (IBusConnection *connection); +IBusConfigService *ibus_config_service_new (GDBusConnection *connection); /** * ibus_config_service_value_changed: * @config: An IBusConfigService. * @section: Section name of the configuration option. * @name: Name of the configure option. - * @value: GValue that holds the value. + * @value: GVariant that holds the value. * * Change a value of a configuration option * by sending a "ValueChanged" message to IBus service. @@ -214,7 +222,7 @@ void ibus_config_service_value_changed (IBusConfigService *config, const gchar *section, const gchar *name, - const GValue *value); + GVariant *value); G_END_DECLS #endif diff --git a/src/ibusconnection.c b/src/ibusconnection.c deleted file mode 100644 index 842f2bc..0000000 --- a/src/ibusconnection.c +++ /dev/null @@ -1,839 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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 -#include -#include "ibusmainloop.h" -#include "ibusmessage.h" -#include "ibusconnection.h" -#include "ibusinternal.h" - -#define IBUS_CONNECTION_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_CONNECTION, IBusConnectionPrivate)) - -enum { - AUTHENTICATE_UNIX_USER, - IBUS_SIGNAL, - IBUS_MESSAGE, - IBUS_MESSAGE_SENT, - DISCONNECTED, - LAST_SIGNAL, -}; - - -/* IBusConnectionPriv */ -struct _IBusConnectionPrivate { - DBusConnection *connection; - gboolean shared; -}; -typedef struct _IBusConnectionPrivate IBusConnectionPrivate; - -static guint connection_signals[LAST_SIGNAL] = { 0 }; - -/* functions prototype */ -static void ibus_connection_destroy (IBusConnection *connection); - -static gboolean ibus_connection_authenticate_unix_user - (IBusConnection *connection, - gulong uid); -static gboolean ibus_connection_ibus_message(IBusConnection *connection, - IBusMessage *message); -static gboolean ibus_connection_ibus_signal (IBusConnection *connection, - IBusMessage *message); -static void ibus_connection_disconnected(IBusConnection *connection); -static DBusHandlerResult - _connection_handle_message_cb(DBusConnection *dbus_connection, - IBusMessage *message, - IBusConnection *connection); - -static GHashTable *_connections = NULL; - -G_DEFINE_TYPE (IBusConnection, ibus_connection, IBUS_TYPE_OBJECT) - -IBusConnection * -ibus_connection_new (void) -{ - GObject *object; - object = g_object_new (IBUS_TYPE_CONNECTION, NULL); - return IBUS_CONNECTION (object); -} - -static void -ibus_connection_class_init (IBusConnectionClass *klass) -{ - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IBusConnectionPrivate)); - - object_class->destroy = (IBusObjectDestroyFunc) ibus_connection_destroy; - - klass->authenticate_unix_user = ibus_connection_authenticate_unix_user; - klass->ibus_message = ibus_connection_ibus_message; - klass->ibus_signal = ibus_connection_ibus_signal; - klass->disconnected = ibus_connection_disconnected; - - /* install signals */ - /** - * IBusConnection::authenticate-unix-user: - * @ibusconnection: The object which received the signal. - * @uid: unix user id. - * - * Emitted when sending an ibus-message. - * Implement the member function ibus_message() in extended class to receive this signal. - * - * Argument @user_data is ignored in this function. - * - * Returns: TRUE if succeed; FALSE otherwise. - */ - connection_signals[AUTHENTICATE_UNIX_USER] = - g_signal_new (I_("authenticate-unix-user"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (IBusConnectionClass, authenticate_unix_user), - NULL, NULL, - ibus_marshal_BOOLEAN__ULONG, - G_TYPE_BOOLEAN, 1, - G_TYPE_ULONG); - - /** - * IBusConnection::ibus-message: - * @ibusconnection: The object which received the signal. - * @message: An IBusMessage. - * - * Emitted when sending an ibus-message. - * Implement the member function ibus_message() in extended class to receive this signal. - * - * Argument @user_data is ignored in this function. - * - * Returns: TRUE if succeed; FALSE otherwise. - */ - connection_signals[IBUS_MESSAGE] = - g_signal_new (I_("ibus-message"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (IBusConnectionClass, ibus_message), - NULL, NULL, - ibus_marshal_BOOLEAN__POINTER, - G_TYPE_BOOLEAN, 1, - G_TYPE_POINTER); - - /** - * IBusConnection::ibus-signal: - * @ibusconnection: The object which received the signal. - * @message: An IBusMessage that contain the signal. - * - * Emitted when sending an ibus-signal. - * Implement the member function ibus_signal() function in extended class to receive this signal. - * - * Argument @user_data is ignored in this function. - * - * Returns: TRUE if succeed; FALSE otherwise. - */ - connection_signals[IBUS_SIGNAL] = - g_signal_new (I_("ibus-signal"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (IBusConnectionClass, ibus_signal), - NULL, NULL, - ibus_marshal_BOOL__POINTER, - G_TYPE_BOOLEAN, 1, - G_TYPE_POINTER); - - /** - * IBusConnection::ibus-message-sent: - * @ibusconnection: The object which received the signal. - * @message: An IBusMessage that contain the signal. - * - * Emitted when an ibus-message is sent. - * Implement the member function ibus_message_sent() function in extended class to receive this signal. - * - * Argument @user_data is ignored in this function. - */ - connection_signals[IBUS_MESSAGE_SENT] = - g_signal_new (I_("ibus-message-sent"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (IBusConnectionClass, ibus_message_sent), - NULL, NULL, - ibus_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - - /** - * IBusConnection::disconnected: - * @ibusconnection: The object which received the signal. - * - * Emitted when an ibus-message is disconnected. - * Implement the member function disconnected() function in extended class to receive this signal. - * - * Argument @user_data is ignored in this function. - * - */ - connection_signals[DISCONNECTED] = - g_signal_new (I_("disconnected"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (IBusConnectionClass, disconnected), - NULL, NULL, - ibus_marshal_VOID__VOID, - G_TYPE_NONE, 0); - -} - -static void -ibus_connection_init (IBusConnection *connection) -{ - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - priv->connection = NULL; - priv->shared = FALSE; -} - -static void -ibus_connection_destroy (IBusConnection *connection) -{ - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - if (priv->connection) { - dbus_connection_remove_filter (priv->connection, - (DBusHandleMessageFunction) _connection_handle_message_cb, - connection); - } - - do { - if (!priv->shared && priv->connection) { - dbus_connection_close (priv->connection); - dbus_connection_unref (priv->connection); - priv->connection = NULL; - break; - } - - if (priv->shared && priv->connection) { - g_warn_if_fail (_connections != NULL); - if (_connections != NULL) { - g_hash_table_remove (_connections, priv->connection); - } - dbus_connection_unref (priv->connection); - priv->connection = NULL; - break; - } - } while (0); - - IBUS_OBJECT_CLASS (ibus_connection_parent_class)->destroy (IBUS_OBJECT (connection)); -} - -static gboolean -ibus_connection_authenticate_unix_user (IBusConnection *connection, - gulong uid) -{ - return FALSE; -} - -static gboolean -ibus_connection_ibus_message (IBusConnection *connection, - IBusMessage *message) -{ - gboolean retval = FALSE; - - if (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_SIGNAL) - g_signal_emit (connection, connection_signals[IBUS_SIGNAL], 0, message, &retval); - - return retval; -} - -static gboolean -ibus_connection_ibus_signal (IBusConnection *connection, IBusMessage *message) -{ - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - if (ibus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")) { - g_signal_emit (connection, connection_signals[DISCONNECTED], 0); - return FALSE; - } - return FALSE; -} - -static void -ibus_connection_disconnected (IBusConnection *connection) -{ - ibus_object_destroy (IBUS_OBJECT (connection)); -} - -static dbus_bool_t -_connection_allow_unix_user_cb (DBusConnection *dbus_connection, - gulong uid, - IBusConnection *connection) -{ - gboolean retval = FALSE; - - g_signal_emit (connection, connection_signals[AUTHENTICATE_UNIX_USER], 0, uid, &retval); - - if (retval) - return TRUE; - - return FALSE; -} - -static DBusHandlerResult -_connection_handle_message_cb (DBusConnection *dbus_connection, - IBusMessage *message, - IBusConnection *connection) -{ - gboolean retval = FALSE; - - g_signal_emit (connection, connection_signals[IBUS_MESSAGE], 0, message, &retval); - - if (retval) - return DBUS_HANDLER_RESULT_HANDLED; - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -static gint -_get_slot () -{ - static gint slot = -1; - if (slot == -1) { - dbus_connection_allocate_data_slot (&slot); - } - return slot; -} - -void -ibus_connection_set_connection (IBusConnection *connection, DBusConnection *dbus_connection, gboolean shared) -{ - gboolean result; - IBusConnectionPrivate *priv; - - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (dbus_connection != NULL); - g_assert (dbus_connection_get_is_connected (dbus_connection)); - - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - g_assert (priv->connection == NULL); - - priv->connection = dbus_connection_ref (dbus_connection); - priv->shared = shared; - - dbus_connection_set_data (priv->connection, _get_slot(), connection, NULL); - - dbus_connection_set_unix_user_function (priv->connection, - (DBusAllowUnixUserFunction) _connection_allow_unix_user_cb, - connection, NULL); - - result = dbus_connection_add_filter (priv->connection, - (DBusHandleMessageFunction) _connection_handle_message_cb, - connection, NULL); - - ibus_dbus_connection_setup (priv->connection); - g_warn_if_fail (result); -} - -static void -_connection_destroy_cb (IBusConnection *connection, - gpointer user_data) -{ - g_hash_table_remove (_connections, user_data); - g_object_unref (connection); -} - -IBusConnection * -ibus_connection_open (const gchar *address) -{ - g_assert (address != NULL); - - DBusError error; - DBusConnection *dbus_connection; - IBusConnection *connection; - - if (_connections == NULL) { - _connections = g_hash_table_new (g_direct_hash, g_direct_equal); - } - - - dbus_error_init (&error); - dbus_connection = dbus_connection_open (address, &error); - if (dbus_connection == NULL) { - g_warning ("Connect to %s failed: %s.", address, error.message); - dbus_error_free (&error); - return NULL; - } - - connection = g_hash_table_lookup (_connections, dbus_connection); - - if (connection == NULL) { - connection = ibus_connection_new (); - g_object_ref_sink (connection); - - ibus_connection_set_connection (connection, dbus_connection, TRUE); - g_hash_table_insert (_connections, dbus_connection, connection); - g_signal_connect (connection, "destroy", G_CALLBACK (_connection_destroy_cb), dbus_connection); - } - - dbus_connection_unref (dbus_connection); - g_object_ref_sink (connection); - return connection; -} - -IBusConnection * -ibus_connection_open_private (const gchar *address) -{ - g_assert (address != NULL); - - DBusError error; - DBusConnection *dbus_connection; - IBusConnection *connection; - - dbus_error_init (&error); - dbus_connection = dbus_connection_open_private (address, &error); - if (dbus_connection == NULL) { - g_warning ("Connect to %s failed. %s.", address, error.message); - dbus_error_free (&error); - return NULL; - } - - connection = ibus_connection_new (); - ibus_connection_set_connection (connection, dbus_connection, FALSE); - - return connection; -} - -void ibus_connection_close (IBusConnection *connection) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - dbus_connection_close (priv->connection); -} - -gboolean -ibus_connection_is_connected (IBusConnection *connection) -{ - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - if (priv->connection == NULL) { - return FALSE; - } - return dbus_connection_get_is_connected (priv->connection); -} - -gboolean -ibus_connection_is_authenticated (IBusConnection *connection) -{ - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - if (priv->connection == NULL) { - return FALSE; - } - return dbus_connection_get_is_authenticated (priv->connection); -} - -DBusConnection * -ibus_connection_get_connection (IBusConnection *connection) -{ - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - return priv->connection; -} - -glong -ibus_connection_get_unix_user (IBusConnection *connection) -{ - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - gulong uid; - - if (priv->connection && dbus_connection_get_unix_user (priv->connection, &uid)) - return uid; - return -1; -} - -gboolean -ibus_connection_read_write_dispatch (IBusConnection *connection, - gint timeout) -{ - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - return dbus_connection_read_write_dispatch (priv->connection, timeout); -} - -typedef struct _VTableCallData { - IBusMessageFunc message_func; - gpointer user_data; -}VTableCallData; - -void -_unregister_function (DBusConnection *dbus_connection, VTableCallData *data) -{ - g_slice_free (VTableCallData, data); -} - -DBusHandlerResult -_message_function (DBusConnection *dbus_connection, - DBusMessage *message, - VTableCallData *data) -{ - gboolean retval; - IBusConnection *connection; - - connection = IBUS_CONNECTION (dbus_connection_get_data (dbus_connection, _get_slot())); - retval = data->message_func (connection, message, data->user_data); - - return retval ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -gboolean -ibus_connection_register_object_path (IBusConnection *connection, - const gchar *path, IBusMessageFunc message_func, gpointer user_data) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (path != NULL); - g_assert (message_func != NULL); - - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - gboolean retval; - DBusObjectPathVTable vtable = {0}; - VTableCallData *data; - - vtable.unregister_function = (DBusObjectPathUnregisterFunction) _unregister_function; - vtable.message_function = (DBusObjectPathMessageFunction) _message_function; - - data = g_slice_new (VTableCallData); - data->message_func = message_func; - data->user_data = user_data; - - retval = dbus_connection_register_object_path (priv->connection, path, &vtable, data); - if (!retval) { - g_warning ("Out of memory!"); - return FALSE; - } - return TRUE; -} - -gboolean -ibus_connection_unregister_object_path (IBusConnection *connection, const gchar *path) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (path != NULL); - - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - gboolean retval; - - retval = dbus_connection_unregister_object_path (priv->connection, path); - if (!retval) { - g_warning ("Out of memory!"); - return FALSE; - } - - return TRUE; -} - - -gboolean -ibus_connection_send (IBusConnection *connection, - IBusMessage *message) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (message != NULL); - - gboolean retval; - IBusConnectionPrivate *priv; - - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - retval = dbus_connection_send (priv->connection, message, NULL); - - if (retval) { - g_signal_emit (connection, - connection_signals[IBUS_MESSAGE_SENT], - 0, - message); - } - - return retval; -} - - -gboolean -ibus_connection_send_signal (IBusConnection *connection, - const gchar *path, - const gchar *interface, - const gchar *name, - GType first_arg_type, - ...) -{ - va_list args; - gboolean retval; - - va_start (args, first_arg_type); - retval = ibus_connection_send_signal_valist (connection, - path, - interface, - name, - first_arg_type, - args); - va_end (args); - return retval; -} - -gboolean -ibus_connection_send_signal_valist (IBusConnection *connection, - const gchar *path, - const gchar *interface, - const gchar *name, - GType first_arg_type, - va_list args) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (interface != NULL); - g_assert (name != NULL); - - gboolean retval; - IBusMessage *message; - - message = ibus_message_new_signal (path, interface, name); - - ibus_message_append_args_valist (message, first_arg_type, args); - retval = ibus_connection_send (connection, message); - ibus_message_unref (message); - - return retval; -} - -gboolean -ibus_connection_send_valist (IBusConnection *connection, - gint message_type, - const gchar *path, - const gchar *interface, - const gchar *name, - GType first_arg_type, - va_list args) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (interface != NULL); - g_assert (name != NULL); - - gboolean retval; - IBusMessage *message; - - message = ibus_message_new (message_type); - ibus_message_set_path (message, path); - ibus_message_set_interface (message, interface); - ibus_message_set_member (message, name); - - ibus_message_append_args_valist (message, first_arg_type, args); - retval = ibus_connection_send (connection, message); - ibus_message_unref (message); - - return retval; -} - -gboolean -ibus_connection_send_with_reply (IBusConnection *connection, - IBusMessage *message, - IBusPendingCall **pending_return, - gint timeout_milliseconds) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (message != NULL); - g_assert (pending_return != NULL); - g_assert (timeout_milliseconds > 0 || timeout_milliseconds == -1); - - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - gboolean retval; - - retval = dbus_connection_send_with_reply (priv->connection, - message, - pending_return, - timeout_milliseconds); - - return retval; -} - -IBusMessage * -ibus_connection_send_with_reply_and_block (IBusConnection *connection, - IBusMessage *message, - gint timeout_milliseconds, - IBusError **error) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (message != NULL); - g_assert (timeout_milliseconds > 0 || timeout_milliseconds == -1); - - IBusError *_error; - IBusMessage *reply; - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - _error = ibus_error_new (); - - reply = dbus_connection_send_with_reply_and_block (priv->connection, - message, - timeout_milliseconds, - _error); - - if (reply != NULL) { - g_signal_emit (connection, - connection_signals[IBUS_MESSAGE_SENT], - 0, - message); - ibus_error_free (_error); - } - else { - if (error != NULL) { - *error = _error; - } - else { - ibus_error_free (_error); - } - } - - return reply; -} - -static IBusMessage * -ibus_connection_call_with_reply_valist (IBusConnection *connection, - const gchar *name, - const gchar *path, - const gchar *interface, - const gchar *member, - IBusError **error, - GType first_arg_type, - va_list va_args) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (name != NULL); - g_assert (path != NULL); - g_assert (interface != NULL); - g_assert (member != NULL); - g_assert (ibus_connection_is_connected (connection)); - - IBusConnectionPrivate *priv; - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - IBusMessage *message, *reply; - IBusError *tmp_error; - - message = ibus_message_new_method_call (name, path, interface, member); - - ibus_message_append_args_valist (message, first_arg_type, va_args); - - reply = ibus_connection_send_with_reply_and_block ( - connection, - message, - -1, - error); - ibus_message_unref (message); - - if (reply == NULL) { - return NULL; - } - - if ((tmp_error = ibus_error_new_from_message (reply)) != NULL) { - if (error) { - *error = tmp_error; - } - else { - ibus_error_free (tmp_error); - } - ibus_message_unref (reply); - return NULL; - } - - return reply; -} - -IBusMessage * -ibus_connection_call_with_reply (IBusConnection *connection, - const gchar *name, - const gchar *path, - const gchar *interface, - const gchar *member, - IBusError **error, - GType first_arg_type, - ...) -{ - IBusMessage *reply; - va_list va_args; - - va_start (va_args, first_arg_type); - reply = ibus_connection_call_with_reply_valist ( - connection, name, path, interface, member, error, - first_arg_type, va_args); - va_end (va_args); - - return reply; -} - -gboolean -ibus_connection_call (IBusConnection *connection, - const gchar *name, - const gchar *path, - const gchar *interface, - const gchar *member, - IBusError **error, - GType first_arg_type, - ...) -{ - IBusMessage *reply; - va_list va_args; - - va_start (va_args, first_arg_type); - reply = ibus_connection_call_with_reply_valist ( - connection, name, path, interface, member, error, - first_arg_type, va_args); - va_end (va_args); - - if (reply) { - ibus_message_unref (reply); - return TRUE; - } - - return FALSE; -} - -void -ibus_connection_flush (IBusConnection *connection) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - g_return_if_fail (ibus_connection_is_connected (connection)); - - IBusConnectionPrivate *priv; - - priv = IBUS_CONNECTION_GET_PRIVATE (connection); - - dbus_connection_flush (priv->connection); -} diff --git a/src/ibusconnection.h b/src/ibusconnection.h deleted file mode 100644 index 7e40d6f..0000000 --- a/src/ibusconnection.h +++ /dev/null @@ -1,520 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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. - */ -/** - * SECTION: ibusconnection - * @short_description: DBusConnection wrapper. - * @title: IBusConnection - * @stability: Stable - * DBusConnection - * - * An IBusConnection provides #DBusConnection wrapper, and is used to connect to either D-Bus or IBus daemon. - * Usually, IBusConnection is set to a #DBusConnection and emitting ibus-message when - * receiving incoming messages from the #DBusConnection. - * - * @see_also: #IBusMessage - * - */ - -#ifndef __IBUS_CONNECTION_H_ -#define __IBUS_CONNECTION_H_ - -#include "ibusdbus.h" -#include "ibusmessage.h" -#include "ibuspendingcall.h" -#include "ibusobject.h" -#include "ibuserror.h" - -/* - * Type macros. - */ - -/* define GOBJECT macros */ -#define IBUS_TYPE_CONNECTION \ - (ibus_connection_get_type ()) -#define IBUS_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_CONNECTION, IBusConnection)) -#define IBUS_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_CONNECTION, IBusConnectionClass)) -#define IBUS_IS_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_CONNECTION)) -#define IBUS_IS_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_CONNECTION)) -#define IBUS_CONNECTION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_CONNECTION, IBusConnectionClass)) - -G_BEGIN_DECLS - -typedef struct _IBusConnection IBusConnection; -typedef struct _IBusConnectionClass IBusConnectionClass; - -/** - * IBusIBusMessageFunc: - * @connection: An IBusConnection. - * @message: An IBusMessage. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Prototype of an IBusIBusMessage callback function. - */ -typedef gboolean (* IBusIBusMessageFunc)(IBusConnection *connection, - IBusMessage *message); - -/** - * IBusIBusSignalFunc: - * @connection: An IBusConnection. - * @message: An IBusMessage. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Prototype of an IBusIBusSignal callback function. - */ -typedef gboolean (* IBusIBusSignalFunc) (IBusConnection *connection, - IBusMessage *message); - -/** - * IBusMessageFunc: - * @connection: An IBusConnection. - * @message: An IBusMessage. - * @user_data: User data for the callback function. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Prototype of an IBusMessage callback function. - */ -typedef gboolean (* IBusMessageFunc) (IBusConnection *connection, - IBusMessage *message, - gpointer user_data); - -/** - * IBusConnectionReplyFunc: - * @connection: An IBusConnection. - * @reply: An IBusMessage. - * @user_data: User data for the callback function. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Prototype of an IBusConnectionReplyFunc callback function. - */ -typedef void (* IBusConnectionReplyFunc) - (IBusConnection *connection, - IBusMessage *reply, - gpointer user_data); - -/** - * IBusConnection: - * - * An opaque data type representing an IBusConnection. - */ -struct _IBusConnection { - IBusObject parent; - /* instance members */ -}; - -struct _IBusConnectionClass { - IBusObjectClass parent; - - /* signals */ - gboolean (* authenticate_unix_user) - (IBusConnection *connection, - gulong uid); - gboolean (* ibus_message) (IBusConnection *connection, - IBusMessage *message); - gboolean (* ibus_signal) (IBusConnection *connection, - IBusMessage *message); - void (* ibus_message_sent) - (IBusConnection *connection, - IBusMessage *message); - void (* disconnected) (IBusConnection *connection); - - /*< private >*/ - /* padding */ - gpointer pdummy[4]; -}; - -GType ibus_connection_get_type (void); - -/** - * ibus_connection_new: - * @returns: An newly allocated IBusConnection. - * - * New an IBusConnection. - */ -IBusConnection *ibus_connection_new (void); - -/** - * ibus_connection_set_connection: - * @connection: An IBusConnection. - * @dbus_connection: A D-Bus connection. - * @shared: Whether the @dbus_connection is shared. - * - * Set an IBusConnection as data of a D-Bus connection. - * Emit signal ibus-message when receiving incoming message from @dbus_connection. - */ -void ibus_connection_set_connection (IBusConnection *connection, - DBusConnection *dbus_connection, - gboolean shared); - -/** - * ibus_connection_open: - * @address: A remote address. - * @returns: A newly allocated IBusConnection which is set to a D-Bus connection corresponding to @address. - * - * Open an IBusConnection that is set to a D-Bus connection to the specified address. - * Use ibus_connection_open_private() to get a dedicated connection not shared with other callers of - * ibus_connection_open(). - * - * @see_also: ibus_connection_open_private(). - */ -IBusConnection *ibus_connection_open (const gchar *address); - -/** - * ibus_connection_open_private: - * @address: A remote address. - * @returns: A newly allocated IBusConnection which is set to a D-Bus connection corresponding to @address. - * - * Open an IBusConnection that is set to a D-Bus connection to the specified address. - * Unlike ibus_connection_open(), this function always creates a new D-Bus connection. - * The D-Bus connection will not be saved or recycled by libdbus. - * - * In D-Bus documentation, dbus_connection_open() is preferred over dbus_connection_open_private(), - * so should ibus_connection_open() be preferred over ibus_connection_open_private(). - * - * @see_also: ibus_connection_open(). - */ -IBusConnection *ibus_connection_open_private (const gchar *address); - -/** - * ibus_connection_close: - * @connection: An IBusConnection. - * - * Close an IBusCOnnection and corresponding D-Bus connection. - */ -void ibus_connection_close (IBusConnection *connection); - -/** - * ibus_connection_is_connected: - * @connection: An IBusConnection. - * @returns: TRUE for connected; FALSE otherwise. - * - * Whether an IBusConnection is connected. - */ -gboolean ibus_connection_is_connected (IBusConnection *connection); - -/** - * ibus_connection_is_authenticated: - * @connection: An IBusConnection. - * @returns: TRUE for authenticated; FALSE otherwise. - * - * Whether an IBusConnection is authenticated. - */ -gboolean ibus_connection_is_authenticated (IBusConnection *connection); - -/** - * ibus_connection_get_connection: - * @connection: An IBusConnection. - * @returns: The corresponding DBusConnection. - * - * Return corresponding DBusConnection. - */ -DBusConnection *ibus_connection_get_connection (IBusConnection *connection); - -/** - * ibus_connection_get_unix_user: - * @connection: An IBusConnection. - * @returns: The UNIX UID of peer user. - * - * Return The UNIX UID of peer user. - */ -glong ibus_connection_get_unix_user (IBusConnection *connection); - -/** - * ibus_connection_read_write_dispatch: - * @connection: An IBusConnection. - * @timeout: Maximum time to block or -1 for infinite. - * @returns: TRUE if the disconnect message has not been processed; FALSE otherwise. - * - * Return TRUE if the disconnect message has not been processed. - * This function is a wrapper of dbus_connection_read_write_dispatch(), - * which is also intended for use with applications that don't want to - * write a main loop and deal with DBusWatch and DBusTimeout. - * Following text is - * from the documentation of dbus_connection_read_write_dispatch(): - * An example usage would be: - * - * - * while (dbus_connection_read_write_dispatch (connection, -1)) - * ; // empty loop body - * - * - * In this usage you would normally have set up a filter function to look at each message as it is dispatched. - * The loop terminates when the last message from the connection (the disconnected signal) is processed. - * - * If there are messages to dispatch, this function will dbus_connection_dispatch() once, and return. - * If there are no messages to dispatch, this function will block until it can read or write, - * then read or write, then return. - * - * The way to think of this function is that it either makes some sort of progress, - * or it blocks. Note that, while it is blocked on I/O, it cannot be interrupted (even by other threads), - * which makes this function unsuitable for applications that do more than just react to received messages. - * - * @see_also: dbus_connection_read_write_dispatch(). - */ -gboolean ibus_connection_read_write_dispatch(IBusConnection *connection, - gint timeout); - -/** - * ibus_connection_send: - * @connection: An IBusConnection. - * @message: IBusMessage to be sent. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Send an IBusMessage to an IBusConnection. - * If succeed, signal ibus-message-sent is emitted. - * - * @see_also: ibus_connection_send_with_reply(), ibus_connection_send_with_reply_and_block(), - * ibus_connection_send_signal(), ibus_connection_send_signal_valist(), ibus_connection_send_valist(), - * dbus_connection_send(). - */ -gboolean ibus_connection_send (IBusConnection *connection, - IBusMessage *message); - -/** - * ibus_connection_send_signal: - * @connection: An IBusConnection. - * @path: The path to the object emitting the signal. - * @interface: The interface the signal is emitted from. - * @name: Name of the signal. - * @first_arg_type: Type of first argument. - * @...: Rest of arguments, NULL to mark the end. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Send a wrapped D-Bus signal to an IBusConnection. - * This function wraps a signal as an IBusMessage, then sent the IBusMessage - * via ibus_connection_send(). - * - * @see_also: ibus_connection_send(), ibus_connection_send_signal_valist(), ibus_message_new_signal(). - */ -gboolean ibus_connection_send_signal (IBusConnection *connection, - const gchar *path, - const gchar *interface, - const gchar *name, - GType first_arg_type, - ...); - -/** - * ibus_connection_send_signal_valist: - * @connection: An IBusConnection. - * @path: The path to the object emitting the signal. - * @interface: The interface the signal is emitted from. - * @name: Name of the signal. - * @first_arg_type: Type of first arg. - * @args: Ret of arguments. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Send a wrapped D-Bus signal to an IBusConnection. - * This function wraps a signal as an IBusMessage, then sent the IBusMessage - * via ibus_connection_send(). - * - * @see_also: ibus_connection_send(), ibus_connection_send_signal(), ibus_connection_send_valist(), - * ibus_message_new_signal(). - */ -gboolean ibus_connection_send_signal_valist (IBusConnection *connection, - const gchar *path, - const gchar *interface, - const gchar *name, - GType first_arg_type, - va_list args); - -/** - * ibus_connection_send_valist: - * @connection: An IBusConnection. - * @message_type: Message type. - * @path: The path to the object emitting the signal. - * @interface: The interface the signal is emitted from. - * @name: Name of the signal. - * @first_arg_type: Type of first arg. - * @args: Ret of arguments. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Send a wrapped D-Bus message to an IBusConnection. - * - * This function wraps a D-Bus message as an IBusMessage, then sent the IBusMessage - * via ibus_connection_send(). - * - * Message type can be specified with @message_type. - * Types include DBUS_MESSAGE_TYPE_METHOD_CALL, - * DBUS_MESSAGE_TYPE_METHOD_RETURN, - * DBUS_MESSAGE_TYPE_ERROR, - * DBUS_MESSAGE_TYPE_SIGNAL, - * but other types are allowed and all code must silently ignore messages of unknown type. - * DBUS_MESSAGE_TYPE_INVALID will never be returned. - * - * @see_also: ibus_connection_send(), ibus_connection_send_singal_valist(), - * ibus_connection_call(), - * ibus_message_new_signal(), - * dbus_message_get_type(). - */ -gboolean ibus_connection_send_valist (IBusConnection *connection, - gint message_type, - const gchar *path, - const gchar *interface, - const gchar *name, - GType first_arg_type, - va_list args); - -/** - * ibus_connection_send_with_reply: - * @connection: An IBusConnection. - * @message: An IBusMessage. - * @pending_return: Return location of a IBusPendingCall object, or NULL if connection is disconnected. - * @timeout_milliseconds: timeout in milliseconds or -1 for default. - * @returns: FALSE if no memory, TRUE otherwise. - * - * Queues an IBusMessage to send, and returns a IBusPendingCall used to receive a reply to the message. - * This function is a wrapper of dbus_connection_send_with_reply(). - * - * @see_also: ibus_connection_send(), ibus_connection_send_with_reply_and_block(), - * ibus_proxy_call_with_reply(), - * #IBusPendingCall, dbus_connection_send_with_reply() - */ -gboolean ibus_connection_send_with_reply (IBusConnection *connection, - IBusMessage *message, - IBusPendingCall **pending_return, - gint timeout_milliseconds); - -/** - * ibus_connection_send_with_reply_and_block: - * @connection: An IBusConnection. - * @message: An IBusMessage. - * @timeout_milliseconds: timeout in milliseconds or -1 for default. - * @error: Returned error is stored here; NULL to ignore error. - * @returns: An IBusMessage that is the reply or NULL with an error code if the function fails. - * - * Sends an IBus message and blocks a certain time period while waiting for - * an IBusMessage as reply. - * If the IBusMessage is not NULL, signal ibus-message-sent is emitted. - * - * @see_also: ibus_connection_send(), ibus_connection_send_with_reply(), - * dbus_connection_send_with_reply_and_block() - */ -IBusMessage *ibus_connection_send_with_reply_and_block - (IBusConnection *connection, - IBusMessage *message, - gint timeout_milliseconds, - IBusError **error); - -/** - * ibus_connection_call: - * @connection: An IBusConnection. - * @name: Name of the signal. - * @path: The path to the object emitting the signal. - * @interface: The interface the signal is emitted from. - * @member: The name of the member function to be called. - * @error: Returned error is stored here; NULL to ignore error. - * @first_arg_type: Type of first argument. - * @...: Rest of arguments, NULL to mark the end. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Invoke a member function by sending an IBusMessage. This method does not - * support reply message, use ibus_connection_call_with_reply instead. - * - * @see_also: ibus_connection_send_valist(). - */ -gboolean ibus_connection_call (IBusConnection *connection, - const gchar *name, - const gchar *path, - const gchar *interface, - const gchar *member, - IBusError **error, - GType first_arg_type, - ...); - -/** - * ibus_connection_call_with_reply: - * @connection: An IBusConnection. - * @name: Name of the signal. - * @path: The path to the object emitting the signal. - * @interface: The interface the signal is emitted from. - * @member: The name of the member function to be called. - * @error: Returned error is stored here; NULL to ignore error. - * @first_arg_type: Type of first argument. - * @...: Rest of arguments, NULL to mark the end. - * @returns: Reply message, or NULL when fail. The returned message must be - * freed with ibus_message_unref(). - * - * Invoke a member function by sending an IBusMessage. - * - * @see_also: ibus_connection_send_valist(). - */ -IBusMessage *ibus_connection_call_with_reply (IBusConnection *connection, - const gchar *name, - const gchar *path, - const gchar *interface, - const gchar *member, - IBusError **error, - GType first_arg_type, - ...); - -/** - * ibus_connection_flush: - * @connection: An IBusConnection. - * - * Blocks until the outgoing message queue is empty. - * This function is a wrapper of dbus_connection_flush(). - * - * @see_also: dbus_connection_flush() - */ -void ibus_connection_flush (IBusConnection *connection); - -/** - * ibus_connection_register_object_path: - * @connection: An IBusConnection. - * @path: Object path to be register. - * @message_func: Callback function for message handling. - * @user_data: User data for @message_func. - * @returns: FALSE if fail because of out of memory; TRUE otherwise. - * - * Registers a handler for a given path in the object hierarchy. - * The given vtable handles messages sent to exactly the given path. - * This function is a wrapper of dbus_connection_register_object_path(). - * - * @see_also: ibus_connection_register_object_path() - */ -gboolean ibus_connection_register_object_path - (IBusConnection *connection, - const gchar *path, - IBusMessageFunc message_func, - gpointer user_data); - -/** - * ibus_connection_unregister_object_path: - * @connection: An IBusConnection. - * @path: Object path to be unregister. - * @returns: FALSE if fail because of out of memory; TRUE otherwise. - * - * Unregisters the handler registered with exactly the given path. - * It's a bug to call this function for a path that isn't registered. - * Can unregister both fallback paths and object paths. - * This function is a wrapper of dbus_connection_unregister_object_path() - */ -gboolean ibus_connection_unregister_object_path - (IBusConnection *connection, - const gchar *path); - -G_END_DECLS -#endif diff --git a/src/ibusdbus.h b/src/ibusdbus.h index 88aa791..3b49250 100644 --- a/src/ibusdbus.h +++ b/src/ibusdbus.h @@ -19,6 +19,11 @@ * 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: ibusdbus * @Title: IBusDBus diff --git a/src/ibusdebug.h b/src/ibusdebug.h index 4e33a96..294164e 100644 --- a/src/ibusdebug.h +++ b/src/ibusdebug.h @@ -19,6 +19,11 @@ * 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: ibusdebug * @short_description: Debug message output. diff --git a/src/ibusengine.c b/src/ibusengine.c index b5f53d4..59de8fa 100644 --- a/src/ibusengine.c +++ b/src/ibusengine.c @@ -19,9 +19,9 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include -#include #include "ibusengine.h" +#include +#include "ibusmarshalers.h" #include "ibusinternal.h" #include "ibusshare.h" @@ -50,124 +50,201 @@ enum { enum { PROP_0, - PROP_NAME, - PROP_CONNECTION, + PROP_ENGINE_NAME, }; /* IBusEnginePriv */ struct _IBusEnginePrivate { - gchar *name; - IBusConnection *connection; + gchar *engine_name; + GDBusConnection *connection; }; -typedef struct _IBusEnginePrivate IBusEnginePrivate; static guint engine_signals[LAST_SIGNAL] = { 0 }; /* functions prototype */ -static void ibus_engine_destroy (IBusEngine *engine); -static void ibus_engine_set_property (IBusEngine *engine, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void ibus_engine_get_property (IBusEngine *engine, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static gboolean ibus_engine_ibus_message (IBusEngine *engine, - IBusConnection *connection, - IBusMessage *message); -static gboolean ibus_engine_process_key_event - (IBusEngine *engine, - guint keyval, - guint keycode, - guint state); -static void ibus_engine_focus_in (IBusEngine *engine); -static void ibus_engine_focus_out (IBusEngine *engine); -static void ibus_engine_reset (IBusEngine *engine); -static void ibus_engine_enable (IBusEngine *engine); -static void ibus_engine_disable (IBusEngine *engine); -static void ibus_engine_set_cursor_location - (IBusEngine *engine, - gint x, - gint y, - gint w, - gint h); -static void ibus_engine_set_capabilities - (IBusEngine *engine, - guint caps); -static void ibus_engine_page_up (IBusEngine *engine); -static void ibus_engine_page_down (IBusEngine *engine); -static void ibus_engine_cursor_up (IBusEngine *engine); -static void ibus_engine_cursor_down (IBusEngine *engine); -static void ibus_engine_candidate_clicked - (IBusEngine *engine, - guint index, - guint button, - guint state); -static void ibus_engine_property_activate - (IBusEngine *engine, - const gchar *prop_name, - guint prop_state); -static void ibus_engine_property_show (IBusEngine *engine, - const gchar *prop_name); -static void ibus_engine_property_hide (IBusEngine *engine, - const gchar *prop_name); +static void ibus_engine_destroy (IBusEngine *engine); +static void ibus_engine_set_property (IBusEngine *engine, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void ibus_engine_get_property (IBusEngine *engine, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void ibus_engine_service_method_call + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation + *invocation); +static GVariant *ibus_engine_service_get_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error); +static gboolean ibus_engine_service_set_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error); +static gboolean ibus_engine_process_key_event + (IBusEngine *engine, + guint keyval, + guint keycode, + guint state); +static void ibus_engine_focus_in (IBusEngine *engine); +static void ibus_engine_focus_out (IBusEngine *engine); +static void ibus_engine_reset (IBusEngine *engine); +static void ibus_engine_enable (IBusEngine *engine); +static void ibus_engine_disable (IBusEngine *engine); +static void ibus_engine_set_cursor_location + (IBusEngine *engine, + gint x, + gint y, + gint w, + gint h); +static void ibus_engine_set_capabilities + (IBusEngine *engine, + guint caps); +static void ibus_engine_page_up (IBusEngine *engine); +static void ibus_engine_page_down (IBusEngine *engine); +static void ibus_engine_cursor_up (IBusEngine *engine); +static void ibus_engine_cursor_down (IBusEngine *engine); +static void ibus_engine_candidate_clicked + (IBusEngine *engine, + guint index, + guint button, + guint state); +static void ibus_engine_property_activate + (IBusEngine *engine, + const gchar *prop_name, + guint prop_state); +static void ibus_engine_property_show (IBusEngine *engine, + const gchar *prop_name); +static void ibus_engine_property_hide (IBusEngine *engine, + const gchar *prop_name); +static void ibus_engine_emit_signal (IBusEngine *engine, + const gchar *signal_name, + GVariant *parameters); G_DEFINE_TYPE (IBusEngine, ibus_engine, IBUS_TYPE_SERVICE) -IBusEngine * -ibus_engine_new (const gchar *name, - const gchar *path, - IBusConnection *connection) -{ - g_assert (path); - g_assert (IBUS_IS_CONNECTION (connection)); - - IBusEngine *engine; - - engine = (IBusEngine *) g_object_new (IBUS_TYPE_ENGINE, - "name", name, - "path", path, - "connection", connection, - NULL); - - return engine; -} +static const gchar introspection_xml[] = + "" + " " + /* FIXME methods */ + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + /* FIXME signals */ + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; static void -ibus_engine_class_init (IBusEngineClass *klass) +ibus_engine_class_init (IBusEngineClass *class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IBusEnginePrivate)); + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (class); gobject_class->set_property = (GObjectSetPropertyFunc) ibus_engine_set_property; gobject_class->get_property = (GObjectGetPropertyFunc) ibus_engine_get_property; ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_engine_destroy; - IBUS_SERVICE_CLASS (klass)->ibus_message = (ServiceIBusMessageFunc) ibus_engine_ibus_message; - - klass->process_key_event = ibus_engine_process_key_event; - klass->focus_in = ibus_engine_focus_in; - klass->focus_out = ibus_engine_focus_out; - klass->reset = ibus_engine_reset; - klass->enable = ibus_engine_enable; - klass->disable = ibus_engine_disable; - klass->page_up = ibus_engine_page_up; - klass->page_down = ibus_engine_page_down; - klass->cursor_up = ibus_engine_cursor_up; - klass->cursor_down = ibus_engine_cursor_down; - klass->candidate_clicked = ibus_engine_candidate_clicked; - klass->property_activate = ibus_engine_property_activate; - klass->property_show = ibus_engine_property_show; - klass->property_hide = ibus_engine_property_hide; - klass->set_cursor_location = ibus_engine_set_cursor_location; - klass->set_capabilities = ibus_engine_set_capabilities; - + IBUS_SERVICE_CLASS (class)->service_method_call = ibus_engine_service_method_call; + IBUS_SERVICE_CLASS (class)->service_get_property = ibus_engine_service_get_property; + IBUS_SERVICE_CLASS (class)->service_set_property = ibus_engine_service_set_property; + + ibus_service_class_add_interfaces (IBUS_SERVICE_CLASS (class), introspection_xml); + + class->process_key_event = ibus_engine_process_key_event; + class->focus_in = ibus_engine_focus_in; + class->focus_out = ibus_engine_focus_out; + class->reset = ibus_engine_reset; + class->enable = ibus_engine_enable; + class->disable = ibus_engine_disable; + class->page_up = ibus_engine_page_up; + class->page_down = ibus_engine_page_down; + class->cursor_up = ibus_engine_cursor_up; + class->cursor_down = ibus_engine_cursor_down; + class->candidate_clicked = ibus_engine_candidate_clicked; + class->property_activate = ibus_engine_property_activate; + class->property_show = ibus_engine_property_show; + class->property_hide = ibus_engine_property_hide; + class->set_cursor_location = ibus_engine_set_cursor_location; + class->set_capabilities = ibus_engine_set_capabilities; /* install properties */ /** @@ -176,25 +253,14 @@ ibus_engine_class_init (IBusEngineClass *klass) * Name of this IBusEngine. */ g_object_class_install_property (gobject_class, - PROP_NAME, - g_param_spec_string ("name", - "name", + PROP_ENGINE_NAME, + g_param_spec_string ("engine-name", + "engine name", "engine name", "noname", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - /** - * IBusEngine:connection: - * - * Connection of this IBusEngine. - */ - g_object_class_install_property (gobject_class, - PROP_CONNECTION, - g_param_spec_object ("connection", - "connection", - "The connection of engine object", - IBUS_TYPE_CONNECTION, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); /* install signals */ /** @@ -221,7 +287,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, process_key_event), NULL, NULL, - ibus_marshal_BOOL__UINT_UINT_UINT, + _ibus_marshal_BOOL__UINT_UINT_UINT, G_TYPE_BOOLEAN, 3, G_TYPE_UINT, @@ -244,7 +310,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, focus_in), NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -264,7 +330,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, focus_out), NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -284,7 +350,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, reset), NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -304,7 +370,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, enable), NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -324,7 +390,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, disable), NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -348,7 +414,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, set_cursor_location), NULL, NULL, - ibus_marshal_VOID__INT_INT_INT_INT, + _ibus_marshal_VOID__INT_INT_INT_INT, G_TYPE_NONE, 4, G_TYPE_INT, @@ -373,7 +439,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, set_capabilities), NULL, NULL, - ibus_marshal_VOID__UINT, + _ibus_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); @@ -393,7 +459,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, page_up), NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -412,7 +478,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, page_down), NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -431,7 +497,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, cursor_up), NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -450,7 +516,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, cursor_down), NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -472,7 +538,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, candidate_clicked), NULL, NULL, - ibus_marshal_VOID__UINT_UINT_UINT, + _ibus_marshal_VOID__UINT_UINT_UINT, G_TYPE_NONE, 3, G_TYPE_UINT, @@ -496,7 +562,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, property_activate), NULL, NULL, - ibus_marshal_VOID__STRING_UINT, + _ibus_marshal_VOID__STRING_UINT, G_TYPE_NONE, 2, G_TYPE_STRING, @@ -518,7 +584,7 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, property_show), NULL, NULL, - ibus_marshal_VOID__STRING, + _ibus_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); @@ -539,35 +605,25 @@ ibus_engine_class_init (IBusEngineClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusEngineClass, property_hide), NULL, NULL, - ibus_marshal_VOID__STRING, + _ibus_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); + g_type_class_add_private (class, sizeof (IBusEnginePrivate)); } static void ibus_engine_init (IBusEngine *engine) { - IBusEnginePrivate *priv; - priv = IBUS_ENGINE_GET_PRIVATE (engine); - - priv->name = NULL; - priv->connection = NULL; + engine->priv = IBUS_ENGINE_GET_PRIVATE (engine); } static void ibus_engine_destroy (IBusEngine *engine) { - IBusEnginePrivate *priv; - priv = IBUS_ENGINE_GET_PRIVATE (engine); - - g_free (priv->name); - - if (priv->connection) { - g_object_unref (priv->connection); - priv->connection = NULL; - } + g_free (engine->priv->engine_name); + engine->priv->engine_name = NULL; IBUS_OBJECT_CLASS(ibus_engine_parent_class)->destroy (IBUS_OBJECT (engine)); } @@ -578,21 +634,10 @@ ibus_engine_set_property (IBusEngine *engine, const GValue *value, GParamSpec *pspec) { - IBusEnginePrivate *priv; - priv = IBUS_ENGINE_GET_PRIVATE (engine); - switch (prop_id) { - case PROP_NAME: - priv->name = g_strdup (g_value_dup_string (value)); - break; - - case PROP_CONNECTION: - priv->connection = g_value_get_object (value); - g_object_ref_sink (priv->connection); - ibus_service_add_to_connection ((IBusService *) engine, - priv->connection); + case PROP_ENGINE_NAME: + engine->priv->engine_name = g_value_dup_string (value); break; - default: G_OBJECT_WARN_INVALID_PROPERTY_ID (engine, prop_id, pspec); } @@ -600,18 +645,13 @@ ibus_engine_set_property (IBusEngine *engine, static void ibus_engine_get_property (IBusEngine *engine, - guint prop_id, GValue *value, GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - IBusEnginePrivate *priv; - priv = IBUS_ENGINE_GET_PRIVATE (engine); - switch (prop_id) { - case PROP_NAME: - g_value_set_string (value, priv->name); - break; - - case PROP_CONNECTION: - g_value_set_object (value, priv->connection); + case PROP_ENGINE_NAME: + g_value_set_string (value, engine->priv->engine_name); break; default: @@ -619,28 +659,45 @@ ibus_engine_get_property (IBusEngine *engine, } } -static gboolean -ibus_engine_ibus_message (IBusEngine *engine, - IBusConnection *connection, - IBusMessage *message) +static void +ibus_engine_service_method_call (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (IBUS_IS_ENGINE (engine)); - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (message != NULL); - g_assert (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL); - - IBusEnginePrivate *priv; - priv = IBUS_ENGINE_GET_PRIVATE (engine); - - g_assert (priv->connection == connection); - - IBusMessage *reply = NULL; - IBusError *error = NULL; - gboolean retval; + IBusEngine *engine = IBUS_ENGINE (service); + + if (g_strcmp0 (interface_name, IBUS_INTERFACE_ENGINE) != 0) { + IBUS_SERVICE_CLASS (ibus_engine_parent_class)-> + service_method_call (service, + connection, + sender, + object_path, + interface_name, + method_name, + parameters, + invocation); + return; + } - gint i; - const gchar *interface; - const gchar *name; + if (g_strcmp0 (method_name, "ProcessKeyEvent") == 0) { + guint keyval, keycode, state; + gboolean retval = FALSE; + g_variant_get (parameters, "(uuu)", &keyval, &keycode, &state); + g_signal_emit (engine, + engine_signals[PROCESS_KEY_EVENT], + 0, + keyval, + keycode, + state, + &retval); + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", retval)); + return; + } static const struct { gchar *member; @@ -657,240 +714,130 @@ ibus_engine_ibus_message (IBusEngine *engine, { "CursorDown", CURSOR_DOWN }, }; - interface = ibus_message_get_interface (message); - name = ibus_message_get_member (message); - - if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_ENGINE) != 0) - return IBUS_SERVICE_CLASS (ibus_engine_parent_class)->ibus_message ( - (IBusService *) engine, connection, message); - - do { - if (g_strcmp0 (name, "ProcessKeyEvent") == 0) { - guint keyval, keycode, state; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_UINT, &keyval, - G_TYPE_UINT, &keycode, - G_TYPE_UINT, &state, - G_TYPE_INVALID); - - if (!retval) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "%s.%s: Can not match signature (uuu) of method", - IBUS_INTERFACE_ENGINE, "ProcessKeyEvent"); - ibus_error_free (error); - } - else { - retval = FALSE; - g_signal_emit (engine, - engine_signals[PROCESS_KEY_EVENT], - 0, - keyval, - keycode, - state, - &retval); - - reply = ibus_message_new_method_return (message); - ibus_message_append_args (reply, - G_TYPE_BOOLEAN, &retval, - G_TYPE_INVALID); - } - break; + gint i; + for (i = 0; i < G_N_ELEMENTS (no_arg_methods); i++) { + if (g_strcmp0 (method_name, no_arg_methods[i].member) == 0) { + g_signal_emit (engine, engine_signals[no_arg_methods[i].signal_id], 0); + g_dbus_method_invocation_return_value (invocation, NULL); + return; } + } - for (i = 0; - i < G_N_ELEMENTS (no_arg_methods) && g_strcmp0 (name, no_arg_methods[i].member) != 0; - i++); - - if (i < G_N_ELEMENTS (no_arg_methods)) { - IBusMessageIter iter; - ibus_message_iter_init (message, &iter); - if (ibus_message_iter_has_next (&iter)) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "%s.%s: Method does not have arguments", - IBUS_INTERFACE_ENGINE, no_arg_methods[i].member); - } - else { - g_signal_emit (engine, engine_signals[no_arg_methods[i].signal_id], 0); - reply = ibus_message_new_method_return (message); - } - break; - } + if (g_strcmp0 (method_name, "CandidateClicked") == 0) { + guint index, button, state; + g_variant_get (parameters, "(uuu)", &index, &button, &state); + g_signal_emit (engine, + engine_signals[CANDIDATE_CLICKED], + 0, + index, + button, + state); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } - if (g_strcmp0 (name, "CandidateClicked") == 0) { - guint index, button, state; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_UINT, &index, - G_TYPE_UINT, &button, - G_TYPE_UINT, &state, - G_TYPE_INVALID); - - if (!retval) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "%s.%s: Can not match signature (uuu) of method", - IBUS_INTERFACE_ENGINE, "CandidateClicked"); - ibus_error_free (error); - } - else { - g_signal_emit (engine, - engine_signals[CANDIDATE_CLICKED], - 0, - index, - button, - state); - reply = ibus_message_new_method_return (message); - } - } - else if (g_strcmp0 (name, "PropertyActivate") == 0) { - gchar *name; - guint state; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &name, - G_TYPE_UINT, &state, - G_TYPE_INVALID); - - if (!retval) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "%s.%s: Can not match signature (si) of method", - IBUS_INTERFACE_ENGINE, - "PropertyActivate"); - ibus_error_free (error); - } - else { - g_signal_emit (engine, - engine_signals[PROPERTY_ACTIVATE], - 0, - name, - state); - - reply = ibus_message_new_method_return (message); - } - } - else if (g_strcmp0 (name, "PropertyShow") == 0) { - gchar *name; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &name, - G_TYPE_INVALID); - - if (!retval) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "%s.%s: Can not match signature (s) of method", - IBUS_INTERFACE_ENGINE, - "PropertyShow"); - ibus_error_free (error); - } - else { - g_signal_emit (engine, - engine_signals[PROPERTY_SHOW], - 0, - name); - - reply = ibus_message_new_method_return (message); - } - } - else if (g_strcmp0 (name, "PropertyHide") == 0) { - gchar *name; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &name, - G_TYPE_INVALID); - if (!retval) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "%s.%s: Can not match signature (s) of method", - IBUS_INTERFACE_ENGINE, "PropertyHide"); - ibus_error_free (error); - } - else { - g_signal_emit (engine, engine_signals[PROPERTY_HIDE], 0, name); - reply = ibus_message_new_method_return (message); - } - } - else if (g_strcmp0 (name, "SetCursorLocation") == 0) { - gint x, y, w, h; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_INT, &x, - G_TYPE_INT, &y, - G_TYPE_INT, &w, - G_TYPE_INT, &h, - G_TYPE_INVALID); - if (!retval) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "%s.%s: Can not match signature (iiii) of method", - IBUS_INTERFACE_ENGINE, - "SetCursorLocation"); - ibus_error_free (error); - } - else { - engine->cursor_area.x = x; - engine->cursor_area.y = y; - engine->cursor_area.width = w; - engine->cursor_area.height = h; - - g_signal_emit (engine, - engine_signals[SET_CURSOR_LOCATION], - 0, - x, y, w, h); - - reply = ibus_message_new_method_return (message); - } - } - else if (g_strcmp0 (name, "SetCapabilities") == 0) { - guint caps; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_UINT, &caps, - G_TYPE_INVALID); - - if (!retval) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "%s.%s: Can not match signature (u) of method", - IBUS_INTERFACE_ENGINE, "SetCapabilities"); - ibus_error_free (error); - } - else { - engine->client_capabilities = caps; - g_signal_emit (engine, engine_signals[SET_CAPABILITIES], 0, caps); - reply = ibus_message_new_method_return (message); - } - } - else if (g_strcmp0 (name, "Destroy") == 0) { - reply = ibus_message_new_method_return (message); - ibus_connection_send (connection, reply); - ibus_message_unref (reply); - ibus_object_destroy ((IBusObject *) engine); - return TRUE; - } - else { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_UNKNOWN_METHOD, - "%s.%s", - IBUS_INTERFACE_ENGINE, name); - g_warn_if_reached (); - } - } while (0); + if (g_strcmp0 (method_name, "PropertyActivate") == 0) { + gchar *name; + guint state; + g_variant_get (parameters, "(&su)", &name, &state); + g_signal_emit (engine, + engine_signals[PROPERTY_ACTIVATE], + 0, + name, + state); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } - ibus_connection_send (connection, reply); - ibus_message_unref (reply); - return TRUE; + if (g_strcmp0 (method_name, "PropertyShow") == 0) { + gchar *name; + g_variant_get (parameters, "(&s)", &name); + g_signal_emit (engine, + engine_signals[PROPERTY_SHOW], + 0, + name); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "PropertyHide") == 0) { + gchar *name; + g_variant_get (parameters, "(&s)", &name); + g_signal_emit (engine, + engine_signals[PROPERTY_HIDE], + 0, + name); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "SetCursorLocation") == 0) { + gint x, y, w, h; + g_variant_get (parameters, "(iiii)", &x, &y, &w, &h); + engine->cursor_area.x = x; + engine->cursor_area.y = y; + engine->cursor_area.width = w; + engine->cursor_area.height = h; + + g_signal_emit (engine, + engine_signals[SET_CURSOR_LOCATION], + 0, + x, y, w, h); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "SetCapabilities") == 0) { + guint caps; + g_variant_get (parameters, "(u)", &caps); + engine->client_capabilities = caps; + g_signal_emit (engine, engine_signals[SET_CAPABILITIES], 0, caps); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + /* should not be reached */ + g_return_if_reached (); +} + +static GVariant * +ibus_engine_service_get_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error) +{ + return IBUS_SERVICE_CLASS (ibus_engine_parent_class)-> + service_get_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + error); +} + +static gboolean +ibus_engine_service_set_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error) +{ + return IBUS_SERVICE_CLASS (ibus_engine_parent_class)-> + service_set_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + value, + error); } static gboolean @@ -1003,6 +950,20 @@ ibus_engine_property_hide (IBusEngine *engine, const gchar *prop_name) } static void +ibus_engine_emit_signal (IBusEngine *engine, + const gchar *signal_name, + GVariant *parameters) +{ + ibus_service_emit_signal ((IBusService *)engine, + NULL, + IBUS_INTERFACE_ENGINE, + signal_name, + parameters, + NULL); +} + +#if 0 +static void _send_signal (IBusEngine *engine, const gchar *name, GType first_arg_type, @@ -1028,15 +989,50 @@ _send_signal (IBusEngine *engine, args); va_end (args); } +#endif + +IBusEngine * +ibus_engine_new (const gchar *engine_name, + const gchar *object_path, + GDBusConnection *connection) +{ + return ibus_engine_new_type (IBUS_TYPE_ENGINE, + engine_name, + object_path, + connection); +} + +IBusEngine * +ibus_engine_new_type (GType engine_type, + const gchar *engine_name, + const gchar *object_path, + GDBusConnection *connection) +{ + g_return_val_if_fail (g_type_is_a (engine_type, IBUS_TYPE_ENGINE), NULL); + g_return_val_if_fail (engine_name != NULL, NULL); + g_return_val_if_fail (object_path != NULL, NULL); + g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); + + GObject *object = g_object_new (engine_type, + "engine-name", engine_name, + "object-path", object_path, + "connection", connection, + NULL); + return IBUS_ENGINE (object); +} + void ibus_engine_commit_text (IBusEngine *engine, IBusText *text) { - _send_signal (engine, - "CommitText", - IBUS_TYPE_TEXT, &text, - G_TYPE_INVALID); + g_return_if_fail (IBUS_IS_ENGINE (engine)); + g_return_if_fail (IBUS_IS_TEXT (text)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)text); + ibus_engine_emit_signal (engine, + "CommitText", + g_variant_new ("(v)", variant)); if (g_object_is_floating (text)) { g_object_unref (text); @@ -1060,75 +1056,49 @@ ibus_engine_update_preedit_text_with_mode (IBusEngine *engine, gboolean visible, IBusPreeditFocusMode mode) { - _send_signal (engine, - "UpdatePreeditText", - IBUS_TYPE_TEXT, &text, - G_TYPE_UINT, &cursor_pos, - G_TYPE_BOOLEAN, &visible, - G_TYPE_UINT, &mode, - G_TYPE_INVALID); + g_return_if_fail (IBUS_IS_ENGINE (engine)); + g_return_if_fail (IBUS_IS_TEXT (text)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)text); + ibus_engine_emit_signal (engine, + "UpdatePreeditText", + g_variant_new ("(vubu)", variant, cursor_pos, visible, mode)); if (g_object_is_floating (text)) { g_object_unref (text); } } -void -ibus_engine_show_preedit_text (IBusEngine *engine) -{ - _send_signal (engine, - "ShowPreeditText", - G_TYPE_INVALID); -} - -void ibus_engine_hide_preedit_text (IBusEngine *engine) -{ - _send_signal (engine, - "HidePreeditText", - G_TYPE_INVALID); -} - void ibus_engine_update_auxiliary_text (IBusEngine *engine, IBusText *text, gboolean visible) { - _send_signal (engine, - "UpdateAuxiliaryText", - IBUS_TYPE_TEXT, &text, - G_TYPE_BOOLEAN, &visible, - G_TYPE_INVALID); + g_return_if_fail (IBUS_IS_ENGINE (engine)); + g_return_if_fail (IBUS_IS_TEXT (text)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)text); + ibus_engine_emit_signal (engine, + "UpdateAuxiliaryText", + g_variant_new ("(vb)", variant, visible)); if (g_object_is_floating (text)) { g_object_unref (text); } } -void -ibus_engine_show_auxiliary_text (IBusEngine *engine) -{ - _send_signal (engine, - "ShowAuxiliaryText", - G_TYPE_INVALID); -} - -void -ibus_engine_hide_auxiliary_text (IBusEngine *engine) -{ - _send_signal (engine, - "HideAuxiliaryText", - G_TYPE_INVALID); -} void ibus_engine_update_lookup_table (IBusEngine *engine, IBusLookupTable *table, gboolean visible) { - _send_signal (engine, - "UpdateLookupTable", - IBUS_TYPE_LOOKUP_TABLE, &table, - G_TYPE_BOOLEAN, &visible, - G_TYPE_INVALID); + g_return_if_fail (IBUS_IS_ENGINE (engine)); + g_return_if_fail (IBUS_IS_LOOKUP_TABLE (table)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)table); + ibus_engine_emit_signal (engine, + "UpdateLookupTable", + g_variant_new ("(vb)", variant, visible)); if (g_object_is_floating (table)) { g_object_unref (table); @@ -1140,6 +1110,9 @@ ibus_engine_update_lookup_table_fast (IBusEngine *engine, IBusLookupTable *table, gboolean visible) { + g_return_if_fail (IBUS_IS_ENGINE (engine)); + g_return_if_fail (IBUS_IS_LOOKUP_TABLE (table)); + IBusLookupTable *new_table; IBusText *text; gint page_begin; @@ -1172,52 +1145,41 @@ ibus_engine_update_lookup_table_fast (IBusEngine *engine, } } -void ibus_engine_show_lookup_table (IBusEngine *engine) -{ - _send_signal (engine, - "ShowLookupTable", - G_TYPE_INVALID); -} - -void ibus_engine_hide_lookup_table (IBusEngine *engine) +void +ibus_engine_forward_key_event (IBusEngine *engine, + guint keyval, + guint keycode, + guint state) { - _send_signal (engine, - "HideLookupTable", - G_TYPE_INVALID); -} + g_return_if_fail (IBUS_IS_ENGINE (engine)); -void ibus_engine_forward_key_event (IBusEngine *engine, - guint keyval, - guint keycode, - guint state) -{ - _send_signal (engine, - "ForwardKeyEvent", - G_TYPE_UINT, &keyval, - G_TYPE_UINT, &keycode, - G_TYPE_UINT, &state, - G_TYPE_INVALID); + ibus_engine_emit_signal (engine, + "ForwardKeyEvent", + g_variant_new ("(uuu)", keyval, keycode, state)); } void ibus_engine_delete_surrounding_text (IBusEngine *engine, gint offset_from_cursor, guint nchars) { - _send_signal (engine, - "DeleteSurroundingText", - G_TYPE_INT, &offset_from_cursor, - G_TYPE_UINT, &nchars, - G_TYPE_INVALID); + g_return_if_fail (IBUS_IS_ENGINE (engine)); + + ibus_engine_emit_signal (engine, + "DeleteSurroundingText", + g_variant_new ("(iu)", offset_from_cursor, nchars)); } void ibus_engine_register_properties (IBusEngine *engine, IBusPropList *prop_list) { - _send_signal (engine, - "RegisterProperties", - IBUS_TYPE_PROP_LIST, &prop_list, - G_TYPE_INVALID); + g_return_if_fail (IBUS_IS_ENGINE (engine)); + g_return_if_fail (IBUS_IS_PROP_LIST (prop_list)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)prop_list); + ibus_engine_emit_signal (engine, + "RegisterProperties", + g_variant_new ("(v)", variant)); if (g_object_is_floating (prop_list)) { g_object_unref (prop_list); @@ -1228,24 +1190,40 @@ void ibus_engine_update_property (IBusEngine *engine, IBusProperty *prop) { - _send_signal (engine, - "UpdateProperty", - IBUS_TYPE_PROPERTY, &prop, - G_TYPE_INVALID); + g_return_if_fail (IBUS_IS_ENGINE (engine)); + g_return_if_fail (IBUS_IS_PROPERTY (prop)); + + GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)prop); + ibus_engine_emit_signal (engine, + "UpdateProperty", + g_variant_new ("(v)", variant)); if (g_object_is_floating (prop)) { g_object_unref (prop); } } +#define DEFINE_FUNC(name, Name) \ + void \ + ibus_engine_##name (IBusEngine *engine) \ + { \ + g_return_if_fail (IBUS_IS_ENGINE (engine)); \ + ibus_engine_emit_signal (engine, \ + #Name, \ + NULL); \ + } +DEFINE_FUNC (show_preedit_text, ShowPreeditText) +DEFINE_FUNC (hide_preedit_text, HidePreeditText) +DEFINE_FUNC (show_auxiliary_text, ShowAuxiliaryText) +DEFINE_FUNC (hide_auxiliary_text, HideAuxiliaryText) +DEFINE_FUNC (show_lookup_table, ShowLookupTable) +DEFINE_FUNC (hide_lookup_table, HideLookupTable) +#undef DEFINE_FUNC + const gchar * ibus_engine_get_name (IBusEngine *engine) { - g_assert (IBUS_IS_ENGINE (engine)); - - IBusEnginePrivate *priv; - priv = IBUS_ENGINE_GET_PRIVATE (engine); - - return priv->name; + g_return_val_if_fail (IBUS_IS_ENGINE (engine), NULL); + return engine->priv->engine_name; } diff --git a/src/ibusengine.h b/src/ibusengine.h index 95be408..46d0a04 100644 --- a/src/ibusengine.h +++ b/src/ibusengine.h @@ -19,6 +19,11 @@ * 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: ibusengine * @short_description: Input method engine abstract. @@ -60,6 +65,7 @@ G_BEGIN_DECLS typedef struct _IBusEngine IBusEngine; typedef struct _IBusEngineClass IBusEngineClass; +typedef struct _IBusEnginePrivate IBusEnginePrivate; /** * IBusEngine: @@ -71,7 +77,10 @@ typedef struct _IBusEngineClass IBusEngineClass; * IBusEngine properties. */ struct _IBusEngine { + /*< private >*/ IBusService parent; + IBusEnginePrivate *priv; + /* instance members */ /*< public >*/ gboolean enabled; @@ -83,9 +92,12 @@ struct _IBusEngine { }; struct _IBusEngineClass { + /*< private >*/ IBusServiceClass parent; /* class members */ + /*< public >*/ + /* signals */ gboolean (* process_key_event) (IBusEngine *engine, guint keyval, @@ -136,14 +148,29 @@ GType ibus_engine_get_type (void); * ibus_engine_new: * @name: Name of the IBusObject. * @path: Path for IBusService. - * @connection: An opened IBusConnection. + * @connection: An opened GDBusConnection. * @returns: A newly allocated IBusEngine. * * New an IBusEngine. */ -IBusEngine *ibus_engine_new (const gchar *name, - const gchar *path, - IBusConnection *connection); +IBusEngine *ibus_engine_new (const gchar *engine_name, + const gchar *object_path, + GDBusConnection *connection); +/** + * ibus_engine_new_type: + * @engine_type: GType of subclass of IBUS_TYPE_ENGINE + * @engine_name: Name of the IBusObject. + * @object_path: Path for IBusService. + * @connection: An opened GDBusConnection. + * @returns: A newly allocated IBusEngine. + * + * New an IBusEngine. + */ +IBusEngine *ibus_engine_new_type (GType engine_type, + const gchar *engine_name, + const gchar *object_path, + GDBusConnection *connection); + /** * ibus_engine_commit_text: diff --git a/src/ibusenginedesc.c b/src/ibusenginedesc.c index aadf6a6..e6550fc 100644 --- a/src/ibusenginedesc.c +++ b/src/ibusenginedesc.c @@ -42,9 +42,9 @@ typedef struct _IBusEngineDescPrivate IBusEngineDescPrivate; /* functions prototype */ static void ibus_engine_desc_destroy (IBusEngineDesc *desc); static gboolean ibus_engine_desc_serialize (IBusEngineDesc *desc, - IBusMessageIter *iter); -static gboolean ibus_engine_desc_deserialize (IBusEngineDesc *desc, - IBusMessageIter *iter); + GVariantBuilder *builder); +static gint ibus_engine_desc_deserialize (IBusEngineDesc *desc, + GVariant *variant); static gboolean ibus_engine_desc_copy (IBusEngineDesc *dest, const IBusEngineDesc *src); static gboolean ibus_engine_desc_parse_xml_node (IBusEngineDesc *desc, @@ -54,18 +54,16 @@ G_DEFINE_TYPE (IBusEngineDesc, ibus_engine_desc, IBUS_TYPE_SERIALIZABLE) static void -ibus_engine_desc_class_init (IBusEngineDescClass *klass) +ibus_engine_desc_class_init (IBusEngineDescClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); - IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); + IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class); object_class->destroy = (IBusObjectDestroyFunc) ibus_engine_desc_destroy; serializable_class->serialize = (IBusSerializableSerializeFunc) ibus_engine_desc_serialize; serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_engine_desc_deserialize; serializable_class->copy = (IBusSerializableCopyFunc) ibus_engine_desc_copy; - - g_string_append (serializable_class->signature, "sssssssssu"); } static void @@ -102,106 +100,49 @@ ibus_engine_desc_destroy (IBusEngineDesc *desc) static gboolean ibus_engine_desc_serialize (IBusEngineDesc *desc, - IBusMessageIter *iter) + GVariantBuilder *builder) { gboolean retval; - retval = IBUS_SERIALIZABLE_CLASS (ibus_engine_desc_parent_class)->serialize ((IBusSerializable *)desc, iter); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &desc->name); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &desc->longname); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &desc->description); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &desc->language); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &desc->license); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &desc->author); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &desc->icon); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &desc->layout); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &desc->hotkeys); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_UINT, &desc->rank); + retval = IBUS_SERIALIZABLE_CLASS (ibus_engine_desc_parent_class)->serialize ((IBusSerializable *)desc, builder); g_return_val_if_fail (retval, FALSE); +#define NOTNULL(s) ((s) != NULL ? (s) : "") + g_variant_builder_add (builder, "s", NOTNULL (desc->name)); + g_variant_builder_add (builder, "s", NOTNULL (desc->longname)); + g_variant_builder_add (builder, "s", NOTNULL (desc->description)); + g_variant_builder_add (builder, "s", NOTNULL (desc->language)); + g_variant_builder_add (builder, "s", NOTNULL (desc->license)); + g_variant_builder_add (builder, "s", NOTNULL (desc->author)); + g_variant_builder_add (builder, "s", NOTNULL (desc->icon)); + g_variant_builder_add (builder, "s", NOTNULL (desc->layout)); + g_variant_builder_add (builder, "s", NOTNULL (desc->hotkeys)); + g_variant_builder_add (builder, "u", desc->rank); +#undef NOTNULL return TRUE; } -static gboolean -ibus_engine_desc_deserialize (IBusEngineDesc *desc, - IBusMessageIter *iter) +static gint +ibus_engine_desc_deserialize (IBusEngineDesc *desc, + GVariant *variant) { - gboolean retval; - gchar *str; - - retval = IBUS_SERIALIZABLE_CLASS (ibus_engine_desc_parent_class)->deserialize ((IBusSerializable *)desc, iter); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - desc->name = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - desc->longname = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - desc->description = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - desc->language = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - desc->license = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - desc->author = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - desc->icon = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - desc->layout = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - desc->hotkeys = g_strdup (str); - - retval = ibus_message_iter_get (iter, G_TYPE_UINT, &desc->rank); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - - return TRUE; + gint retval; + + retval = IBUS_SERIALIZABLE_CLASS (ibus_engine_desc_parent_class)->deserialize ((IBusSerializable *)desc, variant); + g_return_val_if_fail (retval, 0); + + g_variant_get_child (variant, retval++, "s", &desc->name); + g_variant_get_child (variant, retval++, "s", &desc->longname); + g_variant_get_child (variant, retval++, "s", &desc->description); + g_variant_get_child (variant, retval++, "s", &desc->language); + g_variant_get_child (variant, retval++, "s", &desc->license); + g_variant_get_child (variant, retval++, "s", &desc->author); + g_variant_get_child (variant, retval++, "s", &desc->icon); + g_variant_get_child (variant, retval++, "s", &desc->layout); + g_variant_get_child (variant, retval++, "s", &desc->hotkeys); + g_variant_get_child (variant, retval++, "u", &desc->rank); + + return retval; } static gboolean diff --git a/src/ibusenginedesc.h b/src/ibusenginedesc.h index 8f4869c..7c41b35 100644 --- a/src/ibusenginedesc.h +++ b/src/ibusenginedesc.h @@ -19,6 +19,11 @@ * 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: ibusenginedesc * @short_description: Input method engine description data. diff --git a/src/ibusenumtypes.c.template b/src/ibusenumtypes.c.template index a526bd1..9f607a0 100644 --- a/src/ibusenumtypes.c.template +++ b/src/ibusenumtypes.c.template @@ -1,5 +1,4 @@ /*** BEGIN file-header ***/ -#include #include "ibus.h" /*** END file-header ***/ diff --git a/src/ibuserror.c b/src/ibuserror.c deleted file mode 100644 index e701a17..0000000 --- a/src/ibuserror.c +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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 -#include "ibuserror.h" - -IBusError * -ibus_error_new (void) -{ - IBusError *error; - - error = g_slice_new0 (IBusError); - dbus_error_init (error); - - return error; -} - -IBusError * -ibus_error_new_from_text (const gchar *name, - const gchar *message) -{ - IBusError *error = ibus_error_new (); - - dbus_set_error (error, name, "%s", message); - - return error; -} - -IBusError * -ibus_error_new_from_printf (const gchar *name, - const gchar *format_message, - ...) -{ - IBusError *error; - gchar *message; - va_list va_args; - - va_start (va_args, format_message); - message = g_strdup_vprintf (format_message, va_args); - - error = ibus_error_new_from_text (name, message); - g_free (message); - - return error; -} - -IBusError * -ibus_error_new_from_message (IBusMessage *message) -{ - g_assert (message != NULL); - - IBusError *error; - - if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_ERROR) - return NULL; - - error = ibus_error_new (); - - if (dbus_set_error_from_message (error, message)) - return error; - - dbus_error_free (error); - return NULL; -} - -void -ibus_error_free (IBusError *error) -{ - dbus_error_free (error); - g_slice_free (IBusError, error); -} - diff --git a/src/ibuserror.h b/src/ibuserror.h deleted file mode 100644 index 8de6ae0..0000000 --- a/src/ibuserror.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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. - */ -/** - * SECTION: ibuserror - * @short_description: Error message output. - * @stability: Stable - * - * An IBusError is actually a #DBusError. - * Functions listed here are convenient wrapper for IBusError new and free. - */ -#ifndef __IBUS_ERROR_H_ -#define __IBUS_ERROR_H_ - -#include -#include "ibusdbus.h" - -G_BEGIN_DECLS - -/** - * ibus_error_new: - * @returns: A newly allocated IBusError. - * - * New an empty IBusError. - */ -IBusError *ibus_error_new (void); - -/** - * ibus_error_new_from_text: - * @name: The error name. - * @message: Detailed error message. - * @returns: A newly allocated IBusError. - * - * New an IBusError from error name and message. - */ -IBusError *ibus_error_new_from_text (const gchar *name, - const gchar *message); - -/** - * ibus_error_new_from_printf: - * @name: The error name. - * @format_message: printf() formatted error message. - * @...: Formatting parameters. - * @returns: A newly allocated IBusError. - * - * New an IBusError from error name and a printf-formatted message. - */ -IBusError *ibus_error_new_from_printf (const gchar *name, - const gchar *format_message, - ...); - -/** - * ibus_error_new_from_message: - * @message: A DBusMessage - * @returns: A newly allocated IBusError. - * - * New an IBusError from a #IBusMessage. - */ -IBusError *ibus_error_new_from_message - (IBusMessage *message); - -/** - * ibus_error_free: - * @error: An IBusError - * - * Free an IBusError. - */ -void ibus_error_free (IBusError *error); - -G_END_DECLS -#endif diff --git a/src/ibusfactory.c b/src/ibusfactory.c index 0a95108..1133997 100644 --- a/src/ibusfactory.c +++ b/src/ibusfactory.c @@ -19,7 +19,6 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include "ibusfactory.h" #include "ibusengine.h" #include "ibusshare.h" @@ -34,122 +33,112 @@ enum { enum { PROP_0, - PROP_CONNECTION, }; /* IBusFactoryPriv */ struct _IBusFactoryPrivate { guint id; - IBusConnection *connection; GList *engine_list; GHashTable *engine_table; }; -typedef struct _IBusFactoryPrivate IBusFactoryPrivate; /* functions prototype */ -static void ibus_factory_destroy (IBusFactory *factory); -static void ibus_factory_set_property (IBusFactory *engine, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void ibus_factory_get_property (IBusFactory *factory, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static gboolean ibus_factory_ibus_message (IBusFactory *factory, - IBusConnection *connection, - IBusMessage *message); - -static void _engine_destroy_cb (IBusEngine *engine, - IBusFactory *factory); +static void ibus_factory_destroy (IBusFactory *factory); +static void ibus_factory_set_property (IBusFactory *engine, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void ibus_factory_get_property (IBusFactory *factory, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void ibus_factory_service_method_call + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation + *invocation); +static GVariant *ibus_factory_service_get_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error); +static gboolean ibus_factory_service_set_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error); +static void ibus_factory_engine_destroy_cb + (IBusEngine *engine, + IBusFactory *factory); G_DEFINE_TYPE (IBusFactory, ibus_factory, IBUS_TYPE_SERVICE) -IBusFactory * -ibus_factory_new (IBusConnection *connection) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - - IBusFactory *factory; - IBusFactoryPrivate *priv; - - factory = (IBusFactory *) g_object_new (IBUS_TYPE_FACTORY, - "path", IBUS_PATH_FACTORY, - "connection", connection, - NULL); - priv = IBUS_FACTORY_GET_PRIVATE (factory); - - return factory; -} +static const gchar introspection_xml[] = + "" + " " + " " + " " + " " + " " + " " + ""; static void -ibus_factory_class_init (IBusFactoryClass *klass) +ibus_factory_class_init (IBusFactoryClass *class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IBusFactoryPrivate)); + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (class); gobject_class->set_property = (GObjectSetPropertyFunc) ibus_factory_set_property; gobject_class->get_property = (GObjectGetPropertyFunc) ibus_factory_get_property; - ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_factory_destroy; - IBUS_SERVICE_CLASS (klass)->ibus_message = (ServiceIBusMessageFunc) ibus_factory_ibus_message; - - /** - * IBusFactory:connection: - * - * Connection of this IBusFactory. - **/ - g_object_class_install_property (gobject_class, - PROP_CONNECTION, - g_param_spec_object ("connection", - "connection", - "The connection of factory object", - IBUS_TYPE_CONNECTION, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + IBUS_SERVICE_CLASS (class)->service_method_call = ibus_factory_service_method_call; + IBUS_SERVICE_CLASS (class)->service_get_property = ibus_factory_service_get_property; + IBUS_SERVICE_CLASS (class)->service_set_property = ibus_factory_service_set_property; + ibus_service_class_add_interfaces (IBUS_SERVICE_CLASS (class), introspection_xml); + g_type_class_add_private (class, sizeof (IBusFactoryPrivate)); } static void ibus_factory_init (IBusFactory *factory) { - IBusFactoryPrivate *priv; - priv = IBUS_FACTORY_GET_PRIVATE (factory); - - priv->id = 0; - priv->connection = NULL; - priv->engine_table = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - NULL); - priv->engine_list = NULL; + factory->priv = IBUS_FACTORY_GET_PRIVATE (factory); + factory->priv->engine_table = + g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + NULL); } static void ibus_factory_destroy (IBusFactory *factory) { GList *list; - IBusFactoryPrivate *priv; - priv = IBUS_FACTORY_GET_PRIVATE (factory); - list = g_list_copy (priv->engine_list); + list = g_list_copy (factory->priv->engine_list); g_list_foreach (list, (GFunc) ibus_object_destroy, NULL); - g_list_free (priv->engine_list); + g_list_free (factory->priv->engine_list); g_list_free (list); - priv->engine_list = NULL; - - if (priv->engine_table) { - g_hash_table_destroy (priv->engine_table); - } + factory->priv->engine_list = NULL; - if (priv->connection) { - g_object_unref (priv->connection); - priv->connection = NULL; + if (factory->priv->engine_table) { + g_hash_table_destroy (factory->priv->engine_table); } IBUS_OBJECT_CLASS(ibus_factory_parent_class)->destroy (IBUS_OBJECT (factory)); @@ -161,17 +150,15 @@ ibus_factory_set_property (IBusFactory *factory, const GValue *value, GParamSpec *pspec) { - IBusFactoryPrivate *priv; - priv = IBUS_FACTORY_GET_PRIVATE (factory); - switch (prop_id) { + #if 0 case PROP_CONNECTION: priv->connection = g_value_get_object (value); g_object_ref_sink (priv->connection); ibus_service_add_to_connection ((IBusService *) factory, priv->connection); break; - + #endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (factory, prop_id, pspec); } @@ -183,109 +170,133 @@ ibus_factory_get_property (IBusFactory *factory, GValue *value, GParamSpec *pspec) { - IBusFactoryPrivate *priv; - priv = IBUS_FACTORY_GET_PRIVATE (factory); - switch (prop_id) { + #if 0 case PROP_CONNECTION: g_value_set_object (value, priv->connection); break; - + #endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (factory, prop_id, pspec); } } static void -_engine_destroy_cb (IBusEngine *engine, - IBusFactory *factory) +ibus_factory_engine_destroy_cb (IBusEngine *engine, + IBusFactory *factory) { - IBusFactoryPrivate *priv; - priv = IBUS_FACTORY_GET_PRIVATE (factory); - - priv->engine_list = g_list_remove (priv->engine_list, engine); + factory->priv->engine_list = g_list_remove (factory->priv->engine_list, engine); g_object_unref (engine); } -static gboolean -ibus_factory_ibus_message (IBusFactory *factory, - IBusConnection *connection, - IBusMessage *message) +static void +ibus_factory_service_method_call (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - g_assert (IBUS_IS_FACTORY (factory)); - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (message != NULL); - - IBusMessage *reply_message; - IBusFactoryPrivate *priv; - priv = IBUS_FACTORY_GET_PRIVATE (factory); - - g_assert (priv->connection == connection); - - if (ibus_message_is_method_call (message, - IBUS_INTERFACE_FACTORY, - "CreateEngine")) { - gchar *engine_name; - gchar *path; - IBusError *error; - IBusEngine *engine; - gboolean retval; - GType engine_type; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_STRING, &engine_name, - G_TYPE_INVALID); - - if (!retval) { - reply_message = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "The 1st arg should be engine name"); - ibus_connection_send (connection, reply_message); - ibus_message_unref (reply_message); - return TRUE; - } + IBusFactory *factory = IBUS_FACTORY (service); - engine_type = (GType )g_hash_table_lookup (priv->engine_table, engine_name); + if (g_strcmp0 (method_name, "CreateEngine") == 0) { + gchar *engine_name = NULL; + g_variant_get (parameters, "(&s)", &engine_name); + GType engine_type = (GType )g_hash_table_lookup (factory->priv->engine_table, engine_name); if (engine_type == G_TYPE_INVALID) { - reply_message = ibus_message_new_error_printf (message, - DBUS_ERROR_FAILED, - "Can not create engine %s", engine_name); - ibus_connection_send (connection, reply_message); - ibus_message_unref (reply_message); - return TRUE; - + gchar *error_message = g_strdup_printf ("Can not fond engine %s", engine_name); + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_FAILED, + error_message); + g_free (error_message); } + else { + gchar *object_path = g_strdup_printf ("/org/freedesktop/IBus/Engine/%d", + ++factory->priv->id); + IBusEngine *engine = ibus_engine_new_type (engine_type, + engine_name, + object_path, + ibus_service_get_connection ((IBusService *)factory)); + g_assert (engine != NULL); + g_object_ref_sink (engine); + factory->priv->engine_list = g_list_append (factory->priv->engine_list, engine); + g_signal_connect (engine, + "destroy", + G_CALLBACK (ibus_factory_engine_destroy_cb), + factory); + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(o)", object_path)); + g_free (object_path); + } + return; + } - path = g_strdup_printf ("/org/freedesktop/IBus/Engine/%d", ++priv->id); + IBUS_SERVICE_CLASS (ibus_factory_parent_class)-> + service_method_call (service, + connection, + sender, + object_path, + interface_name, + method_name, + parameters, + invocation); +} - engine = g_object_new (engine_type, - "name", engine_name, - "path", path, - "connection", priv->connection, - NULL); +static GVariant * +ibus_factory_service_get_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error) +{ + return IBUS_SERVICE_CLASS (ibus_factory_parent_class)-> + service_get_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + error); +} - priv->engine_list = g_list_append (priv->engine_list, engine); - g_signal_connect (engine, - "destroy", - G_CALLBACK (_engine_destroy_cb), - factory); - - reply_message = ibus_message_new_method_return (message); - ibus_message_append_args (reply_message, - IBUS_TYPE_OBJECT_PATH, &path, - G_TYPE_INVALID); - g_free (path); - ibus_connection_send (connection, reply_message); - ibus_message_unref (reply_message); - return TRUE; - } +static gboolean +ibus_factory_service_set_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error) +{ + return IBUS_SERVICE_CLASS (ibus_factory_parent_class)-> + service_set_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + value, + error); +} - return IBUS_SERVICE_CLASS (ibus_factory_parent_class)->ibus_message ( - (IBusService *)factory, - connection, - message); +IBusFactory * +ibus_factory_new (GDBusConnection *connection) +{ + g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); + + IBusEngine *object = g_object_new (IBUS_TYPE_FACTORY, + "object-path", IBUS_PATH_FACTORY, + "connection", connection, + NULL); + + return IBUS_FACTORY (object); } void @@ -293,12 +304,9 @@ ibus_factory_add_engine (IBusFactory *factory, const gchar *engine_name, GType engine_type) { - g_assert (IBUS_IS_FACTORY (factory)); - g_assert (engine_name); - g_assert (g_type_is_a (engine_type, IBUS_TYPE_ENGINE)); - - IBusFactoryPrivate *priv; - priv = IBUS_FACTORY_GET_PRIVATE (factory); + g_return_if_fail (IBUS_IS_FACTORY (factory)); + g_return_if_fail (engine_name != NULL); + g_return_if_fail (g_type_is_a (engine_type, IBUS_TYPE_ENGINE)); - g_hash_table_insert (priv->engine_table, g_strdup (engine_name), (gpointer) engine_type); + g_hash_table_insert (factory->priv->engine_table, g_strdup (engine_name), (gpointer) engine_type); } diff --git a/src/ibusfactory.h b/src/ibusfactory.h index 515083d..47c06e0 100644 --- a/src/ibusfactory.h +++ b/src/ibusfactory.h @@ -19,6 +19,11 @@ * 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: ibusfactory * @short_description: Factory for creating engine instances. @@ -102,6 +107,7 @@ G_BEGIN_DECLS typedef struct _IBusFactory IBusFactory; typedef struct _IBusFactoryClass IBusFactoryClass; +typedef struct _IBusFactoryPrivate IBusFactoryPrivate; /** * IBusFactory: @@ -109,12 +115,15 @@ typedef struct _IBusFactoryClass IBusFactoryClass; * An opaque data type representing an IBusFactory. */ struct _IBusFactory { + /*< private >*/ IBusService parent; + IBusFactoryPrivate *priv; /* instance members */ }; struct _IBusFactoryClass { + /*< private >*/ IBusServiceClass parent; /* signals */ @@ -134,12 +143,12 @@ GType ibus_factory_get_type (void); /** * ibus_factory_new: - * @connection: An IBusConnection. + * @connection: An GDBusConnection. * @returns: A newly allocated IBusFactory. * * New an IBusFactory. */ -IBusFactory *ibus_factory_new (IBusConnection *connection); +IBusFactory *ibus_factory_new (GDBusConnection *connection); /** * ibus_factory_add_engine: diff --git a/src/ibushotkey.c b/src/ibushotkey.c index 15ca79c..5bde9e2 100644 --- a/src/ibushotkey.c +++ b/src/ibushotkey.c @@ -19,8 +19,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include "ibushotkey.h" +#include "ibusmarshalers.h" #include "ibuskeysyms.h" #include "ibusinternal.h" #include "ibusshare.h" @@ -66,13 +66,13 @@ static gboolean ibus_hotkey_serialize (IBusHotkey *hot static gboolean ibus_hotkey_deserialize (IBusHotkey *hotkey, IBusMessageIter *iter); */ -static void ibus_hotkey_profile_class_init (IBusHotkeyProfileClass *klass); +static void ibus_hotkey_profile_class_init (IBusHotkeyProfileClass *class); static void ibus_hotkey_profile_init (IBusHotkeyProfile *profile); static void ibus_hotkey_profile_destroy (IBusHotkeyProfile *profile); static gboolean ibus_hotkey_profile_serialize (IBusHotkeyProfile *profile, - IBusMessageIter *iter); -static gboolean ibus_hotkey_profile_deserialize(IBusHotkeyProfile *profile, - IBusMessageIter *iter); + GVariantBuilder *builder); +static gint ibus_hotkey_profile_deserialize(IBusHotkeyProfile *profile, + GVariant *variant); static gboolean ibus_hotkey_profile_copy (IBusHotkeyProfile *dest, const IBusHotkeyProfile*src); static void ibus_hotkey_profile_trigger (IBusHotkeyProfile *profile, @@ -203,14 +203,14 @@ ibus_hotkey_profile_get_type (void) } static void -ibus_hotkey_profile_class_init (IBusHotkeyProfileClass *klass) +ibus_hotkey_profile_class_init (IBusHotkeyProfileClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); - IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); + IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class); - parent_class = (IBusSerializableClass *) g_type_class_peek_parent (klass); + parent_class = (IBusSerializableClass *) g_type_class_peek_parent (class); - g_type_class_add_private (klass, sizeof (IBusHotkeyProfilePrivate)); + g_type_class_add_private (class, sizeof (IBusHotkeyProfilePrivate)); object_class->destroy = (IBusObjectDestroyFunc) ibus_hotkey_profile_destroy; @@ -218,9 +218,7 @@ ibus_hotkey_profile_class_init (IBusHotkeyProfileClass *klass) serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_hotkey_profile_deserialize; serializable_class->copy = (IBusSerializableCopyFunc) ibus_hotkey_profile_copy; - klass->trigger = ibus_hotkey_profile_trigger; - - g_string_append (serializable_class->signature, "av"); + class->trigger = ibus_hotkey_profile_trigger; /* install signals */ /** @@ -236,11 +234,11 @@ ibus_hotkey_profile_class_init (IBusHotkeyProfileClass *klass) */ profile_signals[TRIGGER] = g_signal_new (I_("trigger"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, G_STRUCT_OFFSET (IBusHotkeyProfileClass, trigger), NULL, NULL, - ibus_marshal_VOID__UINT_POINTER, + _ibus_marshal_VOID__UINT_POINTER, G_TYPE_NONE, 2, G_TYPE_UINT, @@ -294,26 +292,26 @@ ibus_hotkey_profile_destroy (IBusHotkeyProfile *profile) static gboolean ibus_hotkey_profile_serialize (IBusHotkeyProfile *profile, - IBusMessageIter *iter) + GVariantBuilder *builder) { gboolean retval; - retval = parent_class->serialize ((IBusSerializable *) profile, iter); + retval = parent_class->serialize ((IBusSerializable *) profile, builder); g_return_val_if_fail (retval, FALSE); return TRUE; } -static gboolean +static gint ibus_hotkey_profile_deserialize (IBusHotkeyProfile *profile, - IBusMessageIter *iter) + GVariant *variant) { - gboolean retval; + gint retval; - retval = parent_class->deserialize ((IBusSerializable *) profile, iter); - g_return_val_if_fail (retval, FALSE); + retval = parent_class->deserialize ((IBusSerializable *) profile, variant); + g_return_val_if_fail (retval, 0); - return TRUE; + return retval; } static gboolean diff --git a/src/ibushotkey.h b/src/ibushotkey.h index 018fa2d..9a341f6 100644 --- a/src/ibushotkey.h +++ b/src/ibushotkey.h @@ -19,6 +19,11 @@ * 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: ibushotkey * @short_description: Hotkeys and associated events. diff --git a/src/ibusinputcontext.c b/src/ibusinputcontext.c index b00ad3b..554fdf3 100644 --- a/src/ibusinputcontext.c +++ b/src/ibusinputcontext.c @@ -19,10 +19,11 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include +#include "ibusinputcontext.h" +#include #include "ibusshare.h" #include "ibusinternal.h" -#include "ibusinputcontext.h" +#include "ibusmarshalers.h" #include "ibusattribute.h" #include "ibuslookuptable.h" #include "ibusproplist.h" @@ -65,54 +66,21 @@ static guint context_signals[LAST_SIGNAL] = { 0 }; // static guint context_signals[LAST_SIGNAL] = { 0 }; /* functions prototype */ -static void ibus_input_context_real_destroy (IBusInputContext *context); -static gboolean ibus_input_context_ibus_signal (IBusProxy *proxy, - DBusMessage *message); +static void ibus_input_context_g_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters); G_DEFINE_TYPE (IBusInputContext, ibus_input_context, IBUS_TYPE_PROXY) -IBusInputContext * -ibus_input_context_new (const gchar *path, - IBusConnection *connection) -{ - g_assert (path != NULL); - g_assert (IBUS_IS_CONNECTION (connection)); - GObject *obj; - - obj = g_object_new (IBUS_TYPE_INPUT_CONTEXT, - "name", IBUS_SERVICE_IBUS, - "interface", IBUS_INTERFACE_INPUT_CONTEXT, - "path", path, - "connection", connection, - NULL); - - return IBUS_INPUT_CONTEXT (obj); -} - -IBusInputContext * -ibus_input_context_get_input_context (const gchar *path, - IBusConnection *connection) -{ - IBusInputContext *context = ibus_input_context_new (path, connection); - IBusInputContextPrivate *priv; - if (!context) - return NULL; - priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (context); - priv->own = FALSE; - return context; -} - static void -ibus_input_context_class_init (IBusInputContextClass *klass) +ibus_input_context_class_init (IBusInputContextClass *class) { - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - IBusProxyClass *proxy_class = IBUS_PROXY_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IBusInputContextPrivate)); + GDBusProxyClass *g_dbus_proxy_class = G_DBUS_PROXY_CLASS (class); - ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_input_context_real_destroy; + g_type_class_add_private (class, sizeof (IBusInputContextPrivate)); - proxy_class->ibus_signal = ibus_input_context_ibus_signal; + g_dbus_proxy_class->g_signal = ibus_input_context_g_signal; /* install signals */ /** @@ -123,11 +91,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[ENABLED] = g_signal_new (I_("enabled"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -138,11 +106,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[DISABLED] = g_signal_new (I_("disabled"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -158,11 +126,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[COMMIT_TEXT] = g_signal_new (I_("commit-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT, + _ibus_marshal_VOID__OBJECT, G_TYPE_NONE, 1, IBUS_TYPE_TEXT); @@ -178,11 +146,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[FORWARD_KEY_EVENT] = g_signal_new (I_("forward-key-event"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__UINT_UINT_UINT, + _ibus_marshal_VOID__UINT_UINT_UINT, G_TYPE_NONE, 3, G_TYPE_UINT, @@ -200,11 +168,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[DELETE_SURROUNDING_TEXT] = g_signal_new (I_("delete-surrounding-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__INT_UINT, + _ibus_marshal_VOID__INT_UINT, G_TYPE_NONE, 2, G_TYPE_INT, @@ -225,11 +193,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[UPDATE_PREEDIT_TEXT] = g_signal_new (I_("update-preedit-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT_UINT_BOOLEAN, + _ibus_marshal_VOID__OBJECT_UINT_BOOLEAN, G_TYPE_NONE, 3, IBUS_TYPE_TEXT, @@ -244,11 +212,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[SHOW_PREEDIT_TEXT] = g_signal_new (I_("show-preedit-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -259,11 +227,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[HIDE_PREEDIT_TEXT] = g_signal_new (I_("hide-preedit-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -278,11 +246,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[UPDATE_AUXILIARY_TEXT] = g_signal_new (I_("update-auxiliary-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT_BOOLEAN, + _ibus_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, IBUS_TYPE_TEXT, G_TYPE_BOOLEAN); @@ -295,11 +263,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[SHOW_AUXILIARY_TEXT] = g_signal_new (I_("show-auxiliary-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -310,11 +278,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[HIDE_AUXILIARY_TEXT] = g_signal_new (I_("hide-auxiliary-text"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -331,11 +299,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[UPDATE_LOOKUP_TABLE] = g_signal_new (I_("update-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT_BOOLEAN, + _ibus_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, IBUS_TYPE_LOOKUP_TABLE, G_TYPE_BOOLEAN); @@ -348,11 +316,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[SHOW_LOOKUP_TABLE] = g_signal_new (I_("show-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -363,11 +331,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[HIDE_LOOKUP_TABLE] = g_signal_new (I_("hide-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -378,11 +346,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[PAGE_UP_LOOKUP_TABLE] = g_signal_new (I_("page-up-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -393,11 +361,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[PAGE_DOWN_LOOKUP_TABLE] = g_signal_new (I_("page-down-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -408,11 +376,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[CURSOR_UP_LOOKUP_TABLE] = g_signal_new (I_("cursor-up-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -423,11 +391,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[CURSOR_DOWN_LOOKUP_TABLE] = g_signal_new (I_("cursor-down-lookup-table"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -444,11 +412,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[REGISTER_PROPERTIES] = g_signal_new (I_("register-properties"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT, + _ibus_marshal_VOID__OBJECT, G_TYPE_NONE, 1, IBUS_TYPE_PROP_LIST); @@ -466,11 +434,11 @@ ibus_input_context_class_init (IBusInputContextClass *klass) */ context_signals[UPDATE_PROPERTY] = g_signal_new (I_("update-property"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT, + _ibus_marshal_VOID__OBJECT, G_TYPE_NONE, 1, IBUS_TYPE_PROPERTY); @@ -485,38 +453,18 @@ ibus_input_context_init (IBusInputContext *context) } static void -ibus_input_context_real_destroy (IBusInputContext *context) -{ - IBusInputContextPrivate *priv; - priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (context); - - if (priv->own && ibus_proxy_get_connection ((IBusProxy *) context) != NULL) { - ibus_proxy_call (IBUS_PROXY (context), - "Destroy", - G_TYPE_INVALID); - } - - IBUS_OBJECT_CLASS(ibus_input_context_parent_class)->destroy (IBUS_OBJECT (context)); -} - -static gboolean -ibus_input_context_ibus_signal (IBusProxy *proxy, - IBusMessage *message) +ibus_input_context_g_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters) { 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; + const gchar *signal_name; guint signal_id; } signals [] = { { "Enabled", ENABLED }, @@ -533,200 +481,148 @@ ibus_input_context_ibus_signal (IBusProxy *proxy, { "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) { - /* Forward key event back with IBUS_FORWARD_MASK. And process_key_event will - * not process key event with IBUS_FORWARD_MASK again. */ - 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; + if (g_strcmp0 (signal_name, "CommitText") == 0) { + GVariant *variant = NULL; + g_variant_get (parameters, "(v)", &variant); + IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + g_signal_emit (context, context_signals[COMMIT_TEXT], 0, text); + + if (g_object_is_floating (text)) + g_object_unref (text); + return; + } + if (g_strcmp0 (signal_name, "UpdatePreeditText") == 0) { + GVariant *variant = NULL; + gint32 cursor_pos; + gboolean visible; + g_variant_get (parameters, "(vub)", &variant, &cursor_pos, &visible); + IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + + g_signal_emit (context, + context_signals[UPDATE_PREEDIT_TEXT], + 0, + text, + cursor_pos, + visible); + + if (g_object_is_floating (text)) + g_object_unref (text); + return; + } + + /* lookup signal in table */ + gint i; + for (i = 0; + i < G_N_ELEMENTS (signals) && g_strcmp0 (signal_name, signals[i].signal_name) != 0; + i++); + + if (i < G_N_ELEMENTS (signals)) { + g_signal_emit (context, context_signals[signals[i].signal_id], 0); + return; + } + + if (g_strcmp0 (signal_name, "UpdateAuxiliaryText") == 0) { + GVariant *variant = NULL; + gboolean visible; + g_variant_get (parameters, "(vb)", &variant, &visible); + IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + + g_signal_emit (context, + context_signals[UPDATE_AUXILIARY_TEXT], + 0, + text, + visible); + if (g_object_is_floating (text)) + g_object_unref (text); + return; + } + + if (g_strcmp0 (signal_name, "UpdateLookupTable") == 0) { + GVariant *variant = NULL; + gboolean visible; + g_variant_get (parameters, "(vb)", &variant, &visible); + + IBusLookupTable *table = IBUS_LOOKUP_TABLE (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + + g_signal_emit (context, + context_signals[UPDATE_LOOKUP_TABLE], + 0, + table, + visible); + if (g_object_is_floating (table)) + g_object_unref (table); + return; + + } + + if (g_strcmp0 (signal_name, "RegisterProperties") == 0) { + GVariant *variant = NULL; + g_variant_get (parameters, "(v)", &variant); + + IBusPropList *prop_list = IBUS_PROP_LIST (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + + g_signal_emit (context, + context_signals[REGISTER_PROPERTIES], + 0, + prop_list); + + if (g_object_is_floating (prop_list)) + g_object_unref (prop_list); + return; + } + + if (g_strcmp0 (signal_name, "UpdateProperty") == 0) { + GVariant *variant = NULL; + g_variant_get (parameters, "(v)", &variant); + IBusProperty *prop = IBUS_PROPERTY (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + + g_signal_emit (context, context_signals[UPDATE_PROPERTY], 0, prop); + + if (g_object_is_floating (prop)) + g_object_unref (prop); + return; } - /* some error happens */ - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - return FALSE; + if (g_strcmp0 (signal_name, "ForwardKeyEvent") == 0) { + guint32 keyval; + guint32 keycode; + guint32 state; + + g_variant_get (parameters, 0, "(uuu)", &keyval, &keycode, &state); + + /* Forward key event back with IBUS_FORWARD_MASK. And process_key_event will + * not process key event with IBUS_FORWARD_MASK again. */ + g_signal_emit (context, + context_signals[FORWARD_KEY_EVENT], + 0, + keyval, + keycode, + state | IBUS_FORWARD_MASK); + return; + } + + if (g_strcmp0 (signal_name, "DeleteSurroundingText") == 0) { + gint offset_from_cursor; + guint nchars; + + g_variant_get (parameters, 0, "(iu)", &offset_from_cursor, &nchars); + + g_signal_emit (context, + context_signals[DELETE_SURROUNDING_TEXT], + 0, + offset_from_cursor, + nchars); + return; + } + + G_DBUS_PROXY_CLASS (ibus_input_context_parent_class)->g_signal ( + proxy, sender_name, signal_name, parameters); } typedef struct { @@ -737,56 +633,80 @@ typedef struct { } CallData; static void -_process_key_event_reply_cb (IBusPendingCall *pending, - CallData *call_data) +ibus_input_context_process_key_event_cb (IBusInputContext *context, + GAsyncResult *res, + guint *data) { - IBusMessage *reply_message; - IBusError *error; - gboolean retval = FALSE; + GError *error = NULL; + GVariant *variant = g_dbus_proxy_call_finish ((GDBusProxy *) context, res, &error); - reply_message = dbus_pending_call_steal_reply (pending); - - if (reply_message == NULL) { - /* reply timeout */ - retval = FALSE; - } - else if ((error = ibus_error_new_from_message (reply_message)) != NULL) { - /* some error happens */ - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - retval = FALSE; + gboolean retval = FALSE; + if (variant == NULL) { + g_warning ("%s.ProcessKeyEvent: %s", IBUS_INTERFACE_INPUT_CONTEXT, error->message); + g_error_free (error); } - else if (!ibus_message_get_args (reply_message, - &error, - G_TYPE_BOOLEAN, &retval, - G_TYPE_INVALID)) { - /* can not get return value */ - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - retval = FALSE; + else { + g_variant_get (variant, "(b)", &retval); + g_variant_unref (variant); } if (!retval) { /* Forward key event back with IBUS_FORWARD_MASK. And process_key_event will * not process key event with IBUS_FORWARD_MASK again. */ - g_signal_emit (call_data->context, + g_signal_emit (context, context_signals[FORWARD_KEY_EVENT], 0, - call_data->keyval, - call_data->keycode, - call_data->state | IBUS_FORWARD_MASK); + data[0], + data[1], + data[2] | IBUS_FORWARD_MASK); } + g_slice_free1 (sizeof (guint) << 2, data); +} - if (reply_message != NULL) { - dbus_message_unref (reply_message); - } +IBusInputContext * +ibus_input_context_new (const gchar *path, + GDBusConnection *connection, + GCancellable *cancellable, + GError **error) +{ + g_assert (path != NULL); + g_assert (G_IS_DBUS_CONNECTION (connection)); + + GInitable *initable; + + initable = g_initable_new (IBUS_TYPE_INPUT_CONTEXT, + cancellable, + error, + "g-connection", connection, + "g-name", "org.freedesktop.DBus", + "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + "g-interface-name", IBUS_INTERFACE_INPUT_CONTEXT, + "g-object-path", path, + NULL); + if (initable != NULL) + return IBUS_INPUT_CONTEXT (initable); + return NULL; } -static void -_call_data_free (CallData *call_data) +IBusInputContext * +ibus_input_context_get_input_context (const gchar *path, + GDBusConnection *connection) { - g_object_unref (call_data->context); - g_slice_free (CallData, call_data); + IBusInputContext *context; + GError *error; + + context = ibus_input_context_new (path, connection, NULL, &error); + if (!context) { + g_warning ("%s", error->message); + g_error_free (error); + return NULL; + } + + IBusInputContextPrivate *priv; + priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (context); + priv->own = FALSE; + + return context; } gboolean @@ -797,51 +717,27 @@ ibus_input_context_process_key_event (IBusInputContext *context, { g_assert (IBUS_IS_INPUT_CONTEXT (context)); - IBusPendingCall *pending = NULL; - IBusError *error = NULL; - CallData *call_data; - gboolean retval; - if (state & IBUS_HANDLED_MASK) return TRUE; if (state & IBUS_IGNORED_MASK) return FALSE; - retval = ibus_proxy_call_with_reply ((IBusProxy *) context, - "ProcessKeyEvent", - &pending, - -1, - &error, - G_TYPE_UINT, &keyval, - G_TYPE_UINT, &keycode, - G_TYPE_UINT, &state, - G_TYPE_INVALID); - if (!retval) { - g_debug ("%s: %s", error->name, error->message); - ibus_error_free (error); - return FALSE; - } - - call_data = g_slice_new0 (CallData); - g_object_ref (context); - call_data->context = context; - call_data->keyval = keyval; - call_data->keycode = keycode; - call_data->state = state; - - /* set notify callback to handle the reply from daemon */ - retval = ibus_pending_call_set_notify (pending, - (IBusPendingCallNotifyFunction)_process_key_event_reply_cb, - call_data, - (GDestroyNotify)_call_data_free); - ibus_pending_call_unref (pending); - - if (!retval) { - _call_data_free (call_data); - g_warning ("%s : ProcessKeyEvent", DBUS_ERROR_NO_MEMORY); - return FALSE; - } + guint *data = g_slice_alloc (sizeof (guint) << 2); + data[0] = keyval; + data[1] = keycode; + data[2] = state; + g_dbus_proxy_call ((GDBusProxy *) context, + "ProcessKeyEvent", /* method_name */ + g_variant_new ("(uuu)", + keyval, keycode, state), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + (GAsyncReadyCallback) ibus_input_context_process_key_event_cb, + /* callback */ + data /* user_data */ + ); return TRUE; } @@ -855,13 +751,15 @@ ibus_input_context_set_cursor_location (IBusInputContext *context, { g_assert (IBUS_IS_INPUT_CONTEXT (context)); - ibus_proxy_call ((IBusProxy *) context, - "SetCursorLocation", - G_TYPE_INT, &x, - G_TYPE_INT, &y, - G_TYPE_INT, &w, - G_TYPE_INT, &h, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *) context, + "SetCursorLocation", /* method_name */ + g_variant_new ("(iiii)", x, y, w, h),/* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + NULL, /* callback */ + NULL /* user_data */ + ); } void @@ -869,11 +767,15 @@ ibus_input_context_set_capabilities (IBusInputContext *context, guint32 capabilites) { g_assert (IBUS_IS_INPUT_CONTEXT (context)); - - ibus_proxy_call ((IBusProxy *) context, - "SetCapabilities", - G_TYPE_UINT, &capabilites, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *) context, + "SetCapabilities", /* method_name */ + g_variant_new ("(u)", capabilites), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + NULL, /* callback */ + NULL /* user_data */ + ); } void @@ -882,12 +784,16 @@ ibus_input_context_property_activate (IBusInputContext *context, gint32 state) { g_assert (IBUS_IS_INPUT_CONTEXT (context)); - - ibus_proxy_call ((IBusProxy *) context, - "PropertyActivate", - G_TYPE_STRING, &prop_name, - G_TYPE_INT, &state, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *) context, + "PropertyActivate", /* method_name */ + g_variant_new ("(si)", + prop_name, state), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + NULL, /* callback */ + NULL /* user_data */ + ); } void @@ -895,11 +801,15 @@ ibus_input_context_property_show (IBusInputContext *context, const gchar *prop_name) { g_assert (IBUS_IS_INPUT_CONTEXT (context)); - - ibus_proxy_call ((IBusProxy *) context, - "PropertyShow", - G_TYPE_STRING, &prop_name, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *) context, + "PropertyShow", /* method_name */ + g_variant_new ("(s)", prop_name), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + NULL, /* callback */ + NULL /* user_data */ + ); } void @@ -907,42 +817,41 @@ ibus_input_context_property_hide (IBusInputContext *context, const gchar *prop_name) { g_assert (IBUS_IS_INPUT_CONTEXT (context)); - - ibus_proxy_call ((IBusProxy *) context, - "PropertyHide", - G_TYPE_STRING, &prop_name, - G_TYPE_INVALID); + g_dbus_proxy_call ((GDBusProxy *) context, + "PropertyHide", /* method_name */ + g_variant_new ("(s)", prop_name), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + NULL, /* callback */ + NULL /* user_data */ + ); } gboolean ibus_input_context_is_enabled (IBusInputContext *context) { g_assert (IBUS_IS_INPUT_CONTEXT (context)); - gboolean retval = FALSE; - - IBusMessage *reply_message; - IBusError *error = NULL; - - reply_message = ibus_proxy_call_with_reply_and_block ((IBusProxy *) context, - "IsEnabled", - -1, - &error, - G_TYPE_INVALID); - if (!reply_message) { - g_debug ("%s: %s", error->name, error->message); - ibus_error_free (error); + GVariant *result; + GError *error; + result = g_dbus_proxy_call_sync ((GDBusProxy *) context, + "IsEnabled", /* method_name */ + NULL, /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + &error /* error */ + ); + + if (result == NULL) { + g_warning ("%s.IsEnabled: %s", IBUS_INTERFACE_INPUT_CONTEXT, error->message); + g_error_free (error); return FALSE; } - if (!ibus_message_get_args (reply_message, - &error, - G_TYPE_BOOLEAN, &retval, - G_TYPE_INVALID)) { - g_debug ("%s: %s", error->name, error->message); - ibus_error_free (error); - retval = FALSE; - } - ibus_message_unref (reply_message); + gboolean retval = FALSE; + g_variant_get (result, "(b)", &retval); + g_variant_unref (result); return retval; } @@ -951,33 +860,29 @@ IBusEngineDesc * ibus_input_context_get_engine (IBusInputContext *context) { g_assert (IBUS_IS_INPUT_CONTEXT (context)); - IBusMessage *reply_message; - IBusError *error = NULL; - IBusSerializable *object = NULL; - - reply_message = ibus_proxy_call_with_reply_and_block ((IBusProxy *) context, - "GetEngine", - -1, - &error, - G_TYPE_INVALID); - if (!reply_message) { - g_debug ("%s: %s", error->name, error->message); - ibus_error_free (error); + GVariant *result; + GError *error; + result = g_dbus_proxy_call_sync ((GDBusProxy *) context, + "GetEngine", /* method_name */ + NULL, /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + &error /* error */ + ); + + if (result == NULL) { + g_warning ("%s.GetEngine: %s", IBUS_INTERFACE_INPUT_CONTEXT, error->message); + g_error_free (error); return NULL; } - if (!ibus_message_get_args (reply_message, - &error, - IBUS_TYPE_ENGINE_DESC, &object, - G_TYPE_INVALID)) { - g_debug ("%s: %s", error->name, error->message); - ibus_error_free (error); - ibus_message_unref (reply_message); - return NULL; - } - ibus_message_unref (reply_message); + GVariant *variant = g_variant_get_child_value (result, 0); + IBusEngineDesc *desc = IBUS_ENGINE_DESC (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + g_variant_unref (result); - return IBUS_ENGINE_DESC (object); + return desc; } void @@ -985,21 +890,32 @@ ibus_input_context_set_engine (IBusInputContext *context, const gchar *name) { g_assert (IBUS_IS_INPUT_CONTEXT (context)); - - ibus_proxy_call ((IBusProxy *) context, - "SetEngine", - G_TYPE_STRING, &name, - G_TYPE_INVALID); + g_assert (name); + g_dbus_proxy_call ((GDBusProxy *) context, + "SetEngine", /* method_name */ + g_variant_new ("(s)", name), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + NULL, /* callback */ + NULL /* user_data */ + ); } -#define DEFINE_FUNC(name,Name) \ - void \ - ibus_input_context_##name (IBusInputContext *context) \ - { \ - g_assert (IBUS_IS_INPUT_CONTEXT (context)); \ - ibus_proxy_call ((IBusProxy *) context, \ - #Name, \ - G_TYPE_INVALID); \ +#define DEFINE_FUNC(name, Name) \ + void \ + ibus_input_context_##name (IBusInputContext *context) \ + { \ + g_assert (IBUS_IS_INPUT_CONTEXT (context)); \ + g_dbus_proxy_call ((GDBusProxy *) context, \ + #Name, /* method_name */ \ + NULL, /* parameters */ \ + G_DBUS_CALL_FLAGS_NONE, /* flags */ \ + -1, /* timeout */ \ + NULL, /* cancellable */ \ + NULL, /* callback */ \ + NULL /* user_data */ \ + ); \ } DEFINE_FUNC(focus_in, FocusIn); @@ -1011,6 +927,5 @@ DEFINE_FUNC(cursor_up, CursorUp); DEFINE_FUNC(cursor_down, CursorDown); DEFINE_FUNC(enable, Enable); DEFINE_FUNC(disable, Disable); - #undef DEFINE_FUNC diff --git a/src/ibusinputcontext.h b/src/ibusinputcontext.h index 0d508a1..671b7ce 100644 --- a/src/ibusinputcontext.h +++ b/src/ibusinputcontext.h @@ -19,6 +19,11 @@ * 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: ibusinputcontext * @short_description: IBus input context proxy object. @@ -66,8 +71,8 @@ typedef struct _IBusInputContextClass IBusInputContextClass; * An opaque data type representing an IBusInputContext. */ struct _IBusInputContext { - IBusProxy parent; - /* instance members */ + IBusProxy parent; + /* instance members */ }; struct _IBusInputContextClass { @@ -84,19 +89,24 @@ GType ibus_input_context_get_type (void); /** * ibus_input_context_new: * @path: The path to the object that emitting the signal. - * @connection: An IBusConnection. + * @connection: An GDBusConnection. + * @cancellable: A #GCancellable or %NULL. + * @error: Return location for error or %NULL. + * * @returns: A newly allocated IBusInputContext. * * New an IBusInputContext. */ IBusInputContext *ibus_input_context_new (const gchar *path, - IBusConnection *connection); + GDBusConnection *connection, + GCancellable *cancellable, + GError **error); /** * ibus_input_context_get_input_context: * @path: The path to the object that emitting the signal. - * @connection: An IBusConnection. + * @connection: An GDBusConnection. * @returns: An existing IBusInputContext. * * Gets an existing IBusInputContext. @@ -104,7 +114,7 @@ IBusInputContext IBusInputContext *ibus_input_context_get_input_context (const gchar *path, - IBusConnection *connection); + GDBusConnection *connection); /** * ibus_input_context_process_key_event: diff --git a/src/ibusinternal.c b/src/ibusinternal.c deleted file mode 100644 index c0026c5..0000000 --- a/src/ibusinternal.c +++ /dev/null @@ -1,671 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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 -#include "ibusinternal.h" - -/** - * IBusMessageQueue: - * @source: The parent GSource. - * @connection: The connection to dispatch. - * - * A GSource subclass for dispatching DBusConnection messages. - * We need this on top of the IO handlers, because sometimes - * there are messages to dispatch queued up but no IO pending. - */ -typedef struct -{ - GSource source; - DBusConnection *connection; -} IBusMessageQueue; - -static gboolean message_queue_prepare (GSource *source, - gint *timeout); -static gboolean message_queue_check (GSource *source); -static gboolean message_queue_dispatch (GSource *source, - GSourceFunc callback, - gpointer user_data); - -static const GSourceFuncs message_queue_funcs = { - message_queue_prepare, - message_queue_check, - message_queue_dispatch, - NULL -}; - -static gboolean -message_queue_prepare (GSource *source, - gint *timeout) -{ - DBusConnection *connection = ((IBusMessageQueue *)source)->connection; - - *timeout = -1; - - return (dbus_connection_get_dispatch_status (connection) == DBUS_DISPATCH_DATA_REMAINS); -} - -static gboolean -message_queue_check (GSource *source) -{ - return FALSE; -} - -static gboolean -message_queue_dispatch (GSource *source, - GSourceFunc callback, - gpointer user_data) -{ - DBusConnection *connection = ((IBusMessageQueue *)source)->connection; - - dbus_connection_ref (connection); - - /* Only dispatch once - we don't want to starve other GSource */ - dbus_connection_dispatch (connection); - - dbus_connection_unref (connection); - - return TRUE; -} - -/** - * ConnectionSetup: - * @context: The main context. - * @ios: All IOHandler. - * @timeouts: All TimeoutHandler. - * @connection: NULL if this is really for a server not a connection. - * @message_queue_source: IBusMessageQueue. - * - */ -GSource *message_queue_source; /**< IBusMessageQueue */ -typedef struct -{ - GMainContext *context; /**< the main context */ - GSList *ios; /**< all IOHandler */ - GSList *timeouts; /**< all TimeoutHandler */ - DBusConnection *connection; /**< NULL if this is really for a server not a connection */ - GSource *message_queue_source; /**< IBusMessageQueue */ -} ConnectionSetup; - - -typedef struct -{ - ConnectionSetup *cs; - GSource *source; - DBusWatch *watch; -} IOHandler; - -typedef struct -{ - ConnectionSetup *cs; - GSource *source; - DBusTimeout *timeout; -} TimeoutHandler; - -dbus_int32_t _dbus_gmain_connection_slot = -1; -static dbus_int32_t server_slot = -1; - -static ConnectionSetup* -connection_setup_new (GMainContext *context, - DBusConnection *connection) -{ - ConnectionSetup *cs; - - cs = g_slice_new0 (ConnectionSetup); - - g_assert (context != NULL); - - cs->context = context; - g_main_context_ref (cs->context); - - if (connection) { - cs->connection = connection; - - cs->message_queue_source = g_source_new ((GSourceFuncs *) &message_queue_funcs, - sizeof (IBusMessageQueue)); - ((IBusMessageQueue*)cs->message_queue_source)->connection = connection; - g_source_attach (cs->message_queue_source, cs->context); - } - return cs; -} - -static void -io_handler_source_finalized (gpointer data) -{ - IOHandler *handler; - - handler = data; - - if (handler->watch) - dbus_watch_set_data (handler->watch, NULL, NULL); - - g_slice_free (IOHandler, handler); -} - -static void -io_handler_destroy_source (void *data) -{ - IOHandler *handler; - - handler = data; - - if (handler->source) { - GSource *source = handler->source; - handler->source = NULL; - handler->cs->ios = g_slist_remove (handler->cs->ios, handler); - g_source_destroy (source); - g_source_unref (source); - } -} - -static void -io_handler_watch_freed (void *data) -{ - IOHandler *handler; - - handler = data; - - handler->watch = NULL; - - io_handler_destroy_source (handler); -} - -static gboolean -io_handler_dispatch (GIOChannel *source, - GIOCondition condition, - gpointer data) -{ - IOHandler *handler; - guint dbus_condition = 0; - DBusConnection *connection; - - handler = data; - - connection = handler->cs->connection; - - if (connection) - dbus_connection_ref (connection); - - if (condition & G_IO_IN) - dbus_condition |= DBUS_WATCH_READABLE; - if (condition & G_IO_OUT) - dbus_condition |= DBUS_WATCH_WRITABLE; - if (condition & G_IO_ERR) - dbus_condition |= DBUS_WATCH_ERROR; - if (condition & G_IO_HUP) - dbus_condition |= DBUS_WATCH_HANGUP; - - /* Note that we don't touch the handler after this, because - * dbus may have disabled the watch and thus killed the - * handler. - */ - dbus_watch_handle (handler->watch, dbus_condition); - handler = NULL; - - if (connection) - dbus_connection_unref (connection); - - return TRUE; -} - -static void -connection_setup_add_watch (ConnectionSetup *cs, - DBusWatch *watch) -{ - guint flags; - GIOCondition condition; - GIOChannel *channel; - IOHandler *handler; - - if (!dbus_watch_get_enabled (watch)) - return; - - g_assert (dbus_watch_get_data (watch) == NULL); - - flags = dbus_watch_get_flags (watch); - - condition = G_IO_ERR | G_IO_HUP; - if (flags & DBUS_WATCH_READABLE) - condition |= G_IO_IN; - if (flags & DBUS_WATCH_WRITABLE) - condition |= G_IO_OUT; - - handler = g_slice_new (IOHandler); - handler->cs = cs; - handler->watch = watch; - - channel = g_io_channel_unix_new (dbus_watch_get_unix_fd (watch)); - - handler->source = g_io_create_watch (channel, condition); - g_source_set_callback (handler->source, (GSourceFunc) io_handler_dispatch, handler, - io_handler_source_finalized); - g_source_attach (handler->source, cs->context); - - cs->ios = g_slist_prepend (cs->ios, handler); - - dbus_watch_set_data (watch, handler, io_handler_watch_freed); - g_io_channel_unref (channel); -} - -static void -connection_setup_remove_watch (ConnectionSetup *cs, - DBusWatch *watch) -{ - IOHandler *handler; - - handler = dbus_watch_get_data (watch); - - if (handler == NULL) - return; - - io_handler_destroy_source (handler); -} - -static void -timeout_handler_source_finalized (gpointer data) -{ - TimeoutHandler *handler; - - handler = data; - - if (handler->timeout) - dbus_timeout_set_data (handler->timeout, NULL, NULL); - - g_slice_free (TimeoutHandler, handler); -} - -static void -timeout_handler_destroy_source (void *data) -{ - TimeoutHandler *handler; - - handler = data; - - if (handler->source) { - GSource *source = handler->source; - handler->source = NULL; - handler->cs->timeouts = g_slist_remove (handler->cs->timeouts, handler); - g_source_destroy (source); - g_source_unref (source); - } -} - -static void -timeout_handler_timeout_freed (void *data) -{ - TimeoutHandler *handler; - - handler = data; - - handler->timeout = NULL; - - timeout_handler_destroy_source (handler); -} - -static gboolean -timeout_handler_dispatch (gpointer data) -{ - TimeoutHandler *handler; - - handler = data; - - dbus_timeout_handle (handler->timeout); - - return TRUE; -} - -static void -connection_setup_add_timeout (ConnectionSetup *cs, - DBusTimeout *timeout) -{ - TimeoutHandler *handler; - - if (!dbus_timeout_get_enabled (timeout)) - return; - - g_assert (dbus_timeout_get_data (timeout) == NULL); - - handler = g_slice_new0 (TimeoutHandler); - handler->cs = cs; - handler->timeout = timeout; - - handler->source = g_timeout_source_new (dbus_timeout_get_interval (timeout)); - g_source_set_callback (handler->source, timeout_handler_dispatch, handler, - timeout_handler_source_finalized); - g_source_attach (handler->source, handler->cs->context); - - cs->timeouts = g_slist_prepend (cs->timeouts, handler); - - dbus_timeout_set_data (timeout, handler, timeout_handler_timeout_freed); -} - -static void -connection_setup_remove_timeout (ConnectionSetup *cs, - DBusTimeout *timeout) -{ - TimeoutHandler *handler; - - handler = dbus_timeout_get_data (timeout); - - if (handler == NULL) - return; - - timeout_handler_destroy_source (handler); -} - -static void -connection_setup_free (ConnectionSetup *cs) -{ - while (cs->ios) - io_handler_destroy_source (cs->ios->data); - - while (cs->timeouts) - timeout_handler_destroy_source (cs->timeouts->data); - - if (cs->message_queue_source) { - GSource *source; - - source = cs->message_queue_source; - cs->message_queue_source = NULL; - - g_source_destroy (source); - g_source_unref (source); - } - - g_main_context_unref (cs->context); - g_slice_free (ConnectionSetup, cs); -} - -static dbus_bool_t -add_watch (DBusWatch *watch, - gpointer data) -{ - ConnectionSetup *cs; - - cs = data; - - connection_setup_add_watch (cs, watch); - - return TRUE; -} - -static void -remove_watch (DBusWatch *watch, - gpointer data) -{ - ConnectionSetup *cs; - - cs = data; - - connection_setup_remove_watch (cs, watch); -} - -static void -watch_toggled (DBusWatch *watch, - void *data) -{ - /* Because we just exit on OOM, enable/disable is - * no different from add/remove - */ - if (dbus_watch_get_enabled (watch)) - add_watch (watch, data); - else - remove_watch (watch, data); -} - -static dbus_bool_t -add_timeout (DBusTimeout *timeout, - void *data) -{ - ConnectionSetup *cs; - - cs = data; - - if (!dbus_timeout_get_enabled (timeout)) - return TRUE; - - connection_setup_add_timeout (cs, timeout); - - return TRUE; -} - -static void -remove_timeout (DBusTimeout *timeout, - void *data) -{ - ConnectionSetup *cs; - - cs = data; - - connection_setup_remove_timeout (cs, timeout); -} - -static void -timeout_toggled (DBusTimeout *timeout, - void *data) -{ - /* Because we just exit on OOM, enable/disable is - * no different from add/remove - */ - if (dbus_timeout_get_enabled (timeout)) - add_timeout (timeout, data); - else - remove_timeout (timeout, data); -} - -static void -wakeup_main (void *data) -{ - ConnectionSetup *cs = data; - - g_main_context_wakeup (cs->context); -} - - -/* Move to a new context */ -static ConnectionSetup* -connection_setup_new_from_old (GMainContext *context, - ConnectionSetup *old) -{ - GSList *tmp; - ConnectionSetup *cs; - - g_assert (old->context != context); - - cs = connection_setup_new (context, old->connection); - - tmp = old->ios; - while (tmp != NULL) { - IOHandler *handler = tmp->data; - - connection_setup_add_watch (cs, handler->watch); - - tmp = tmp->next; - } - - tmp = old->timeouts; - while (tmp != NULL) { - TimeoutHandler *handler = tmp->data; - - connection_setup_add_timeout (cs, handler->timeout); - - tmp = tmp->next; - } - - return cs; -} - -/** @} */ /* End of GLib bindings internals */ - -/* @addtogroup IBusLib - * @{ - */ - -/** - * dbus_connection_setup_with_g_main: - * @connection: the connection - * @context: the #GMainContext or #NULL for default context - * - * Sets the watch and timeout functions of a #DBusConnection - * to integrate the connection with the GLib main loop. - * Pass in #NULL for the #GMainContext unless you're - * doing something specialized. - * - * If called twice for the same context, does nothing the second - * time. If called once with context A and once with context B, - * context B replaces context A as the context monitoring the - * connection. - */ -void -dbus_connection_setup (DBusConnection *connection, - GMainContext *context) -{ - ConnectionSetup *old_setup; - ConnectionSetup *cs; - - do { - /* FIXME we never free the slot, so its refcount just keeps growing, - * which is kind of broken. - */ - dbus_connection_allocate_data_slot (&_dbus_gmain_connection_slot); - if (_dbus_gmain_connection_slot < 0) - break; - - if (context == NULL) - context = g_main_context_default (); - - cs = NULL; - - old_setup = dbus_connection_get_data (connection, _dbus_gmain_connection_slot); - if (old_setup != NULL) { - if (old_setup->context == context) - return; /* nothing to do */ - - cs = connection_setup_new_from_old (context, old_setup); - - /* Nuke the old setup */ - dbus_connection_set_data (connection, _dbus_gmain_connection_slot, NULL, NULL); - old_setup = NULL; - } - - if (cs == NULL) - cs = connection_setup_new (context, connection); - - if (!dbus_connection_set_data (connection, _dbus_gmain_connection_slot, cs, - (DBusFreeFunction)connection_setup_free)) - break; - - if (!dbus_connection_set_watch_functions (connection, - add_watch, - remove_watch, - watch_toggled, - cs, NULL)) - break; - - if (!dbus_connection_set_timeout_functions (connection, - add_timeout, - remove_timeout, - timeout_toggled, - cs, NULL)) - break; - - dbus_connection_set_wakeup_main_function (connection, - wakeup_main, - cs, NULL); - - return; - } while (0); - - g_error ("Not enough memory to set up DBusConnection for use with GLib"); -} - -/** - * dbus_server_setup_with_g_main: - * @server: the server - * @context: the #GMainContext or #NULL for default - * - * Sets the watch and timeout functions of a #DBusServer - * to integrate the server with the GLib main loop. - * In most cases the context argument should be #NULL. - * - * If called twice for the same context, does nothing the second - * time. If called once with context A and once with context B, - * context B replaces context A as the context monitoring the - * connection. - */ -void -dbus_server_setup (DBusServer *server, - GMainContext *context) -{ - ConnectionSetup *old_setup; - ConnectionSetup *cs; - - do { - /* FIXME we never free the slot, so its refcount just keeps growing, - * which is kind of broken. - */ - dbus_server_allocate_data_slot (&server_slot); - if (server_slot < 0) - break; - - if (context == NULL) - context = g_main_context_default (); - - cs = NULL; - - old_setup = dbus_server_get_data (server, server_slot); - if (old_setup != NULL) { - if (old_setup->context == context) - return; /* nothing to do */ - - cs = connection_setup_new_from_old (context, old_setup); - - /* Nuke the old setup */ - dbus_server_set_data (server, server_slot, NULL, NULL); - old_setup = NULL; - } - - if (cs == NULL) - cs = connection_setup_new (context, NULL); - - if (!dbus_server_set_data (server, server_slot, cs, - (DBusFreeFunction)connection_setup_free)) - break; - - if (!dbus_server_set_watch_functions (server, - add_watch, - remove_watch, - watch_toggled, - cs, NULL)) - break; - - if (!dbus_server_set_timeout_functions (server, - add_timeout, - remove_timeout, - timeout_toggled, - cs, NULL)) - break; - - return; - } while (0); - - g_error ("Not enough memory to set up DBusServer for use with GLib"); -} - diff --git a/src/ibusinternal.h b/src/ibusinternal.h index 413070c..6feb5f3 100644 --- a/src/ibusinternal.h +++ b/src/ibusinternal.h @@ -19,23 +19,24 @@ * 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: ibusinternal - * @short_description: IBus DBus setting functions for internal use. + * @short_description: IBus internal. * @title: IBusInternal * @stability: Stable * * This section contain several IBus house keeping functions. * - * @see_also: #IBusMainLoop - * */ #ifndef __IBUS_INTERNEL_H_ #define __IBUS_INTERNEL_H_ #include -#include "ibusdbus.h" - /** * I_: * @string: A string @@ -46,42 +47,5 @@ */ #define I_(string) g_intern_static_string (string) -/** - * dbus_server_setup: - * @server: the server - * @context: the #GMainContext or #NULL for default - * - * Sets the watch and timeout functions of a #DBusServer - * to integrate the server with the GLib main loop. - * In most cases the context argument should be #NULL. - * - * If called twice for the same context, does nothing the second - * time. If called once with context A and once with context B, - * context B replaces context A as the context monitoring the - * connection. - */ -void dbus_server_setup (DBusServer *server, - GMainContext *context); - -/** - * dbus_connection_setup: - * @connection: the connection - * @context: the #GMainContext or #NULL for default context - * - * Sets the watch and timeout functions of a #DBusConnection - * to integrate the connection with the GLib main loop. - * Pass in #NULL for the #GMainContext unless you're - * doing something specialized. - * - * If called twice for the same context, does nothing the second - * time. If called once with context A and once with context B, - * context B replaces context A as the context monitoring the - * connection. - */ -void dbus_connection_setup (DBusConnection *connection, - GMainContext *context); - - - #endif diff --git a/src/ibuskeymap.c b/src/ibuskeymap.c index 26f7dbc..b624263 100644 --- a/src/ibuskeymap.c +++ b/src/ibuskeymap.c @@ -33,14 +33,14 @@ typedef guint KEYMAP[256][7]; static void ibus_keymap_destroy (IBusKeymap *keymap); static gboolean ibus_keymap_load (const gchar *name, KEYMAP keymap); -static GHashTable *keymaps = NULL; +static GHashTable *keymaps = NULL; G_DEFINE_TYPE (IBusKeymap, ibus_keymap, IBUS_TYPE_OBJECT) static void -ibus_keymap_class_init (IBusKeymapClass *klass) +ibus_keymap_class_init (IBusKeymapClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); object_class->destroy = (IBusObjectDestroyFunc) ibus_keymap_destroy; } diff --git a/src/ibuskeymap.h b/src/ibuskeymap.h index 131760b..9221bab 100644 --- a/src/ibuskeymap.h +++ b/src/ibuskeymap.h @@ -19,6 +19,11 @@ * 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: ibuskeymap * @short_description: Keyboard mapping handling. diff --git a/src/ibuskeysyms.h b/src/ibuskeysyms.h index 7438a67..b0420ca 100644 --- a/src/ibuskeysyms.h +++ b/src/ibuskeysyms.h @@ -18,6 +18,11 @@ * 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: ibuskeysyms * @short_description: Key symbol definition. diff --git a/src/ibuslookuptable.c b/src/ibuslookuptable.c index 0d8144f..9782f39 100644 --- a/src/ibuslookuptable.c +++ b/src/ibuslookuptable.c @@ -19,33 +19,30 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include "ibuslookuptable.h" /* functions prototype */ static void ibus_lookup_table_destroy (IBusLookupTable *table); static gboolean ibus_lookup_table_serialize (IBusLookupTable *table, - IBusMessageIter *iter); -static gboolean ibus_lookup_table_deserialize (IBusLookupTable *table, - IBusMessageIter *iter); + GVariantBuilder *builder); +static gint ibus_lookup_table_deserialize (IBusLookupTable *table, + GVariant *variant); static gboolean ibus_lookup_table_copy (IBusLookupTable *dest, IBusLookupTable *src); G_DEFINE_TYPE (IBusLookupTable, ibus_lookup_table, IBUS_TYPE_SERIALIZABLE) static void -ibus_lookup_table_class_init (IBusLookupTableClass *klass) +ibus_lookup_table_class_init (IBusLookupTableClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); - IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); + IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class); object_class->destroy = (IBusObjectDestroyFunc) ibus_lookup_table_destroy; serializable_class->serialize = (IBusSerializableSerializeFunc) ibus_lookup_table_serialize; serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_lookup_table_deserialize; serializable_class->copy = (IBusSerializableCopyFunc) ibus_lookup_table_copy; - - g_string_append (serializable_class->signature, "uubbiavav"); } static void @@ -85,140 +82,82 @@ ibus_lookup_table_destroy (IBusLookupTable *table) static gboolean ibus_lookup_table_serialize (IBusLookupTable *table, - IBusMessageIter *iter) + GVariantBuilder *builder) { - IBusMessageIter array_iter; gboolean retval; guint i; - retval = IBUS_SERIALIZABLE_CLASS (ibus_lookup_table_parent_class)->serialize ((IBusSerializable *)table, iter); - g_return_val_if_fail (retval, FALSE); - - g_return_val_if_fail (IBUS_IS_LOOKUP_TABLE (table), FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_UINT, &table->page_size); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_UINT, &table->cursor_pos); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_BOOLEAN, &table->cursor_visible); - g_return_val_if_fail (retval, FALSE); + retval = IBUS_SERIALIZABLE_CLASS (ibus_lookup_table_parent_class)->serialize ((IBusSerializable *)table, builder); + g_return_val_if_fail (retval, 0); - retval = ibus_message_iter_append (iter, G_TYPE_BOOLEAN, &table->round); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_INT, &table->orientation); - g_return_val_if_fail (retval, FALSE); + g_return_val_if_fail (IBUS_IS_LOOKUP_TABLE (table), 0); - // append candidates - retval = ibus_message_iter_open_container (iter, - IBUS_TYPE_ARRAY, - "v", - &array_iter); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "u", table->page_size); + g_variant_builder_add (builder, "u", table->cursor_pos); + g_variant_builder_add (builder, "b", table->cursor_visible); + g_variant_builder_add (builder, "b", table->round); + g_variant_builder_add (builder, "i", table->orientation); + GVariantBuilder array; + /* append candidates */ + g_variant_builder_init (&array, G_VARIANT_TYPE ("av")); for (i = 0;; i++) { - IBusText *text; - - text = ibus_lookup_table_get_candidate (table, i); + IBusText *text = ibus_lookup_table_get_candidate (table, i); if (text == NULL) break; - - retval = ibus_message_iter_append (&array_iter, IBUS_TYPE_TEXT, &text); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (&array, "v", ibus_serializable_serialize ((IBusSerializable *)text)); } + g_variant_builder_add (builder, "av", &array); - retval = ibus_message_iter_close_container (iter, &array_iter); - g_return_val_if_fail (retval, FALSE); - - // append labels - retval = ibus_message_iter_open_container (iter, - IBUS_TYPE_ARRAY, - "v", - &array_iter); - g_return_val_if_fail (retval, FALSE); - + /* append labels */ + g_variant_builder_init (&array, G_VARIANT_TYPE ("av")); for (i = 0;; i++) { - IBusText *text; - - text = ibus_lookup_table_get_label (table, i); + IBusText *text = ibus_lookup_table_get_label (table, i); if (text == NULL) break; - retval = ibus_message_iter_append (&array_iter, IBUS_TYPE_TEXT, &text); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (&array, "v", ibus_serializable_serialize ((IBusSerializable *)text)); } - - retval = ibus_message_iter_close_container (iter, &array_iter); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "av", &array); return TRUE; } -static gboolean +static gint ibus_lookup_table_deserialize (IBusLookupTable *table, - IBusMessageIter *iter) + GVariant *variant) { - DBusMessageIter array_iter; - gboolean retval; - - retval = IBUS_SERIALIZABLE_CLASS (ibus_lookup_table_parent_class)->deserialize ((IBusSerializable *)table, iter); - g_return_val_if_fail (retval, FALSE); - - g_return_val_if_fail (IBUS_IS_LOOKUP_TABLE (table), FALSE); - - retval = ibus_message_iter_get (iter, G_TYPE_UINT, &table->page_size); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - - retval = ibus_message_iter_get (iter, G_TYPE_UINT, &table->cursor_pos); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); + gint retval; - retval = ibus_message_iter_get (iter, G_TYPE_BOOLEAN, &table->cursor_visible); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); + retval = IBUS_SERIALIZABLE_CLASS (ibus_lookup_table_parent_class)->deserialize ((IBusSerializable *)table, variant); + g_return_val_if_fail (retval, 0); - retval = ibus_message_iter_get (iter, G_TYPE_BOOLEAN, &table->round); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); + g_return_val_if_fail (IBUS_IS_LOOKUP_TABLE (table), 0); - retval = ibus_message_iter_get (iter, G_TYPE_INT, &table->orientation); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); + g_variant_get_child (variant, retval++, "u", &table->page_size); + g_variant_get_child (variant, retval++, "u", &table->cursor_pos); + g_variant_get_child (variant, retval++, "b", &table->cursor_visible); + g_variant_get_child (variant, retval++, "b", &table->round); + g_variant_get_child (variant, retval++, "i", &table->orientation); + GVariant *var; // deserialize candidates - retval = ibus_message_iter_recurse (iter, IBUS_TYPE_ARRAY, &array_iter); - g_return_val_if_fail (retval, FALSE); - - while (ibus_message_iter_get_arg_type (&array_iter) != G_TYPE_INVALID) { - IBusText *text; - retval = ibus_message_iter_get (&array_iter, IBUS_TYPE_TEXT, &text); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (&array_iter); - - ibus_lookup_table_append_candidate (table, text); + GVariantIter *iter = NULL; + g_variant_get_child (variant, retval++, "av", &iter); + while (g_variant_iter_loop (iter, "v", &var)) { + ibus_lookup_table_append_candidate (table, IBUS_TEXT (ibus_serializable_deserialize (var))); } - - ibus_message_iter_next (iter); + g_variant_iter_free (iter); // deserialize labels - retval = ibus_message_iter_recurse (iter, IBUS_TYPE_ARRAY, &array_iter); - g_return_val_if_fail (retval, FALSE); - - while (ibus_message_iter_get_arg_type (&array_iter) != G_TYPE_INVALID) { - IBusText *text; - retval = ibus_message_iter_get (&array_iter, IBUS_TYPE_TEXT, &text); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (&array_iter); - - ibus_lookup_table_append_label (table, text); + iter = NULL; + g_variant_get_child (variant, retval++, "av", &iter); + while (g_variant_iter_loop (iter, "v", &var)) { + ibus_lookup_table_append_label (table, IBUS_TEXT (ibus_serializable_deserialize (var))); } + g_variant_iter_free (iter); - ibus_message_iter_next (iter); - - return TRUE; + return retval; } static gboolean diff --git a/src/ibuslookuptable.h b/src/ibuslookuptable.h index dfa9151..53d08d3 100644 --- a/src/ibuslookuptable.h +++ b/src/ibuslookuptable.h @@ -19,6 +19,11 @@ * 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: ibuslookuptable * @short_description: Candidate word/phrase lookup table. diff --git a/src/ibusmainloop.c b/src/ibusmainloop.c deleted file mode 100644 index 968876b..0000000 --- a/src/ibusmainloop.c +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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 "ibusmainloop.h" -#include "ibusinternal.h" - -static DBusConnectionSetupFunc _connection_setup_func = (DBusConnectionSetupFunc) dbus_connection_setup; -static DBusServerSetupFunc _server_setup_func = (DBusServerSetupFunc) dbus_server_setup; -static gpointer _user_data = NULL; - -void -ibus_mainloop_setup (DBusConnectionSetupFunc connection_func, - DBusServerSetupFunc server_func, - gpointer user_data) -{ - _connection_setup_func = connection_func; - _server_setup_func = server_func; - _user_data = user_data; -} - -void -ibus_dbus_connection_setup (DBusConnection *connection) -{ - if (_connection_setup_func != NULL) - (_connection_setup_func) (connection, _user_data); -} - -void -ibus_dbus_server_setup (DBusServer *server) -{ - if (_server_setup_func != NULL) - (_server_setup_func) (server, _user_data); -} - diff --git a/src/ibusmainloop.h b/src/ibusmainloop.h deleted file mode 100644 index 71118a7..0000000 --- a/src/ibusmainloop.h +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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. - */ -/** - * SECTION: ibusmainloop - * @short_description: DBus server and connection setup functions. - * @stability: Stable - * - * This section defines the DBus server and connection setup functions, - * and prototypes of their callback functions. - */ - -#ifndef __IBUS_MAINLOOP_H_ -#define __IBUS_MAINLOOP_H_ - -#include -#include "ibusdbus.h" - -/** - * DBusConnectionSetupFunc: - * @connection: A DBusConnection - * @user_data: User data to be passed to callback function. - * - * A prototype of callback to DBus connection setup function. - */ -typedef void (* DBusConnectionSetupFunc) (DBusConnection *connection, - gpointer user_data); - -/** - * DBusServerSetupFunc: - * @server: A DBusConnection - * @user_data: User data to be passed to callback function. - * - * A prototype of DBus server setup function. - */ -typedef void (* DBusServerSetupFunc) (DBusServer *server, - gpointer user_data); - -/** - * ibus_mainloop_setup: - * @connection_func: A DBus connection setup function. - * @server_func: A prototype of DBus server setup function. - * @user_data: User data to be passed to callback function. - * - * Sets the watch and timeout functions of a #DBusConnection - * and #DBusServer to integrate the connection with the GLib main loop. - * - * Parameter @user_data should be in type #GMainContext. - * It will be passed to both callback functions, - * however, normally %NULL is sufficient. - * - * If called twice for the same user_data, does nothing the second - * time. If called once with user_data A and once with user_data B, - * user_data B replaces user_data A as the context monitoring the - * connection. - * - * @see_also: ibus_dbus_connection_setup(), ibus_dbus_server_setup(). - */ -void ibus_mainloop_setup (DBusConnectionSetupFunc connection_func, - DBusServerSetupFunc server_func, - gpointer user_data); - -/** - * ibus_dbus_server_setup: - * @server: A DBusServer. - * - * Sets the watch and timeout functions of a #DBusServer - * to integrate the server with the GLib main loop. - * - * This function uses the parameter @user_data and - * server_func set with ibus_mainloop_setup(), - * or fall back to NULL and dbus_server_setup() if those are not defined. - * - * @see_also: ibus_mainloop_setup(), dbus_server_setup(). - */ -void ibus_dbus_server_setup (DBusServer *server); - -/** - * ibus_dbus_connection_setup: - * @connection: A DBusConnection. - * - * Sets the watch and timeout functions of a #DBusConnection - * to integrate the connection with the GLib main loop. - * - * This function uses the parameter @user_data and - * connection_func set with ibus_mainloop_setup(), - * or fall back to NULL and dbus_connection_setup() if those are not defined. - * - * @see_also: ibus_mainloop_setup(), dbus_connection_setup(). - */ -void ibus_dbus_connection_setup (DBusConnection *connection); - -#endif - diff --git a/src/ibusmarshalers.list b/src/ibusmarshalers.list index 4473dab..5184278 100644 --- a/src/ibusmarshalers.list +++ b/src/ibusmarshalers.list @@ -18,7 +18,7 @@ VOID:OBJECT,UINT,BOOL,UINT VOID:OBJECT,BOOL VOID:BOXED,BOOL VOID:BOXED -VOID:STRING,STRING,BOXED +VOID:STRING,STRING,VARIANT VOID:STRING,STRING,STRING VOID:UINT VOID:UINT,POINTER diff --git a/src/ibusmessage.c b/src/ibusmessage.c deleted file mode 100644 index ee2b427..0000000 --- a/src/ibusmessage.c +++ /dev/null @@ -1,1027 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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 -#include "ibusmessage.h" -#include "ibusserializable.h" -#include "ibusconfigprivate.h" - -GType -ibus_type_get_object_path (void) -{ - static GType type = 0; - - if (type == 0) { - type = g_type_register_static_simple ( - G_TYPE_STRING, - "IBusObjectPath", - 0, - NULL, - 0, - NULL, - G_TYPE_FLAG_ABSTRACT); - } - return type; -} - -GType -ibus_type_get_array (void) -{ - static GType type = 0; - - if (type == 0) { - type = g_type_register_static_simple ( - G_TYPE_BOXED, - "IBusArray", - 0, - NULL, - 0, - NULL, - G_TYPE_FLAG_ABSTRACT); - } - return type; -} - -GType -ibus_type_get_struct (void) -{ - static GType type = 0; - - if (type == 0) { - type = g_type_register_static_simple ( - G_TYPE_BOXED, - "IBusStruct", - 0, - NULL, - 0, - NULL, - G_TYPE_FLAG_ABSTRACT); - } - return type; -} - -GType -ibus_type_get_dict_entry (void) -{ - static GType type = 0; - - if (type == 0) { - type = g_type_register_static_simple ( - G_TYPE_BOXED, - "IBusDictEntry", - 0, - NULL, - 0, - NULL, - G_TYPE_FLAG_ABSTRACT); - } - return type; -} - -GType -ibus_type_get_variant (void) -{ - static GType type = 0; - - if (type == 0) { - type = g_type_register_static_simple (G_TYPE_BOXED, - "IBusVariant", - 0, - NULL, - 0, - NULL, - 0); - } - return type; -} - -IBusMessage * -ibus_message_new (gint message_type) -{ - return dbus_message_new (message_type); -} - -IBusMessage * -ibus_message_ref (IBusMessage *message) -{ - return dbus_message_ref (message); -} - -void -ibus_message_unref (IBusMessage *message) -{ - dbus_message_unref (message); -} - -IBusMessage * -ibus_message_new_method_call (const gchar *destination, - const gchar *path, - const gchar *interface, - const gchar *method) -{ - return dbus_message_new_method_call (destination, - path, - interface, - method); -} - -IBusMessage * -ibus_message_new_method_return (IBusMessage *reply_to) -{ - return dbus_message_new_method_return (reply_to); -} - -IBusMessage * -ibus_message_new_error (IBusMessage *reply_to, - const gchar *error_name, - const gchar *error_message) -{ - return dbus_message_new_error (reply_to, - error_name, - error_message); -} - -IBusMessage * -ibus_message_new_error_printf (IBusMessage *reply_to, - const gchar *error_name, - const gchar *error_format, - ...) -{ - va_list va_args; - gchar *error_message; - IBusMessage *message; - - va_start (va_args, error_format); - error_message = g_strdup_vprintf (error_format, va_args); - va_end (va_args); - - message = ibus_message_new_error (reply_to, - error_name, - error_message); - g_free (error_message); - - return message; -} - -IBusMessage * -ibus_message_new_signal (const gchar *path, - const gchar *interface, - const gchar *name) -{ - return dbus_message_new_signal (path, - interface, - name); -} - -gboolean -ibus_message_is_method_call (IBusMessage *message, - const gchar *interface, - const gchar *method) -{ - return dbus_message_is_method_call (message, - interface, - method); -} - -gboolean -ibus_message_is_error (IBusMessage *message, - const gchar *error_name) -{ - return dbus_message_is_error (message, error_name); -} - -gboolean -ibus_message_is_signal (IBusMessage *message, - const gchar *interface, - const gchar *signal_name) -{ - return dbus_message_is_signal (message, - interface, - signal_name); -} - -gboolean -ibus_message_set_destination (IBusMessage *message, - const gchar *destination) -{ - return dbus_message_set_destination (message, destination); -} - -gboolean -ibus_message_set_sender (IBusMessage *message, - const gchar *sender) -{ - return dbus_message_set_sender (message, sender); -} - -gboolean -ibus_message_set_error_name (IBusMessage *message, - const gchar *error_name) -{ - return dbus_message_set_error_name (message, error_name); -} - -gboolean -ibus_message_set_interface (IBusMessage *message, - const gchar *interface) -{ - return dbus_message_set_interface (message, interface); -} - -gboolean -ibus_message_set_member (IBusMessage *message, - const gchar *member) -{ - return dbus_message_set_member (message, member); -} - -gboolean -ibus_message_set_path (IBusMessage *message, - const gchar *path) -{ - return dbus_message_set_path (message, path); -} - -void -ibus_message_set_no_reply (IBusMessage *message, - gboolean no_reply) -{ - dbus_message_set_no_reply (message, no_reply); -} - -gboolean -ibus_message_set_reply_serial (IBusMessage *message, - guint32 reply_serial) -{ - return dbus_message_set_reply_serial (message, reply_serial); -} - -gint -ibus_message_get_type (IBusMessage *message) -{ - return dbus_message_get_type (message); -} - -const gchar * -ibus_message_get_destination (IBusMessage *message) -{ - return dbus_message_get_destination (message); -} - -const gchar * -ibus_message_get_sender (IBusMessage *message) -{ - return dbus_message_get_sender (message); -} - -const gchar * -ibus_message_get_error_name (IBusMessage *message) -{ - return dbus_message_get_error_name (message); -} - -const gchar * -ibus_message_get_error_message (IBusMessage *message) -{ - gchar *error_message; - gboolean retval; - - retval = ibus_message_get_args (message, NULL, G_TYPE_STRING, &error_message, G_TYPE_INVALID); - - if (retval) - return error_message; - return NULL; -} - -const gchar * -ibus_message_get_interface (IBusMessage *message) -{ - return dbus_message_get_interface (message); -} - -const gchar * -ibus_message_get_member (IBusMessage *message) -{ - return dbus_message_get_member (message); -} - -const gchar * -ibus_message_get_path (IBusMessage *message) -{ - return dbus_message_get_path (message); -} - -gboolean -ibus_message_get_no_reply (IBusMessage *message) -{ - return dbus_message_get_no_reply (message); -} - -guint32 -ibus_message_get_reply_serial (IBusMessage *message) -{ - return dbus_message_get_reply_serial (message); -} - -guint32 -ibus_message_get_serial (IBusMessage *message) -{ - return dbus_message_get_serial (message); -} - -gboolean -ibus_message_append_args (IBusMessage *message, - GType first_arg_type, - ...) -{ - gboolean retval; - va_list va_args; - - va_start (va_args, first_arg_type); - retval = ibus_message_append_args_valist (message, - first_arg_type, - va_args); - va_end (va_args); - - return retval; -} - -gboolean -ibus_message_append_args_valist (IBusMessage *message, - GType first_arg_type, - va_list va_args) -{ - GType type; - gboolean retval; - IBusMessageIter iter; - - ibus_message_iter_init_append (message, &iter); - - type = first_arg_type; - while (type != G_TYPE_INVALID) { - gpointer value = va_arg (va_args, gpointer); - retval = ibus_message_iter_append (&iter, type, value); - type = va_arg (va_args, GType); - - g_return_val_if_fail (retval, FALSE); - } - - return TRUE; -} - -gboolean -ibus_message_get_args (IBusMessage *message, - IBusError **error, - GType first_arg_type, - ...) -{ - gboolean retval; - va_list va_args; - - va_start (va_args, first_arg_type); - retval = ibus_message_get_args_valist (message, - error, - first_arg_type, - va_args); - va_end (va_args); - - return retval; - -} - -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; -} - -void -ibus_message_iter_init_append (IBusMessage *message, - IBusMessageIter *iter) -{ - dbus_message_iter_init_append (message, iter); -} - -gboolean -ibus_message_iter_append (IBusMessageIter *iter, - GType type, - gconstpointer value) -{ - g_assert (iter != NULL); - g_assert (type != G_TYPE_INVALID); - g_assert (value != NULL); - - switch (type) { - case G_TYPE_CHAR: - { - char v; - v = * (gchar *)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_BYTE, &v); - } - case G_TYPE_INT: - { - dbus_int32_t v; - v = * (gint *)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_INT32, &v); - } - case G_TYPE_UINT: - { - dbus_uint32_t v; - v = * (guint *)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT32, &v); - } - case G_TYPE_LONG: - { - dbus_int64_t v; - v = * (glong *)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_INT64, &v); - } - case G_TYPE_ULONG: - { - dbus_uint64_t v; - v = * (gulong *)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT64, &v); - } - case G_TYPE_BOOLEAN: - { - dbus_bool_t v; - v = * (gboolean *)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_BOOLEAN, &v); - } - case G_TYPE_STRING: - { - const gchar *v; - v = *(gchar **)value != NULL ? * (gchar **)value : ""; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &v); - } - case G_TYPE_INT64: - { - dbus_int64_t v; - v = * (gint64 *)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_INT64, &v); - } - case G_TYPE_UINT64: - { - dbus_uint64_t v; - v = * (guint64 *)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT64, &v); - } - case G_TYPE_FLOAT: - { - double v; - v = * (gfloat *)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &v); - } - - case G_TYPE_DOUBLE: - { - double v; - v = * (gdouble *)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &v); - } - default: - if (type == G_TYPE_VALUE) { - _to_dbus_value (iter, (GValue *)value); - return TRUE; - } - if (type == IBUS_TYPE_OBJECT_PATH) { - const gchar *v; - v = * (gchar **)value; - return dbus_message_iter_append_basic (iter, DBUS_TYPE_OBJECT_PATH, &v); - } - - if (g_type_is_a (type, IBUS_TYPE_SERIALIZABLE)) { - return ibus_serializable_serialize (*(IBusSerializable **)value, iter); - } - } - - return FALSE; -} - -static gboolean -gtype_is_basic (GType type) -{ - switch (type) { - case G_TYPE_CHAR: - case G_TYPE_INT: - case G_TYPE_UINT: - case G_TYPE_INT64: - case G_TYPE_UINT64: - case G_TYPE_BOOLEAN: - case G_TYPE_DOUBLE: - case G_TYPE_STRING: - return TRUE; - default: - if (type == IBUS_TYPE_OBJECT_PATH) - return TRUE; - return FALSE; - } -} - -gboolean -ibus_message_iter_copy_data (IBusMessageIter *dst, - IBusMessageIter *src) -{ - GType type; - gboolean retval; - - type = ibus_message_iter_get_arg_type (src); - - g_return_val_if_fail (type != G_TYPE_INVALID, FALSE); - - if (gtype_is_basic (type)) { - gchar data[16]; - ibus_message_iter_get_basic (src, data); - retval = ibus_message_iter_append (dst, type, data); - g_return_val_if_fail (retval, FALSE); - return TRUE; - } - - if (type == IBUS_TYPE_VARIANT) { - IBusMessageIter subdst, subsrc; - gchar *signature; - - retval = ibus_message_iter_recurse (src, IBUS_TYPE_VARIANT, &subsrc); - g_return_val_if_fail (retval, FALSE); - - signature = dbus_message_iter_get_signature (&subsrc); - g_return_val_if_fail (signature != NULL, FALSE); - retval = ibus_message_iter_open_container (dst, - IBUS_TYPE_VARIANT, - signature, - &subdst); - dbus_free (signature); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_copy_data (&subdst, &subsrc); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_close_container (dst, &subdst); - g_return_val_if_fail (retval, FALSE); - - return TRUE; - } - else if (type == IBUS_TYPE_ARRAY) { - IBusMessageIter subdst, subsrc; - gchar *signature; - - retval = ibus_message_iter_recurse (src, IBUS_TYPE_ARRAY, &subsrc); - g_return_val_if_fail (retval, FALSE); - - signature = dbus_message_iter_get_signature (src); - g_return_val_if_fail (signature != NULL, FALSE); - - retval = ibus_message_iter_open_container (dst, - IBUS_TYPE_ARRAY, - signature + 1, - &subdst); - dbus_free (signature); - g_return_val_if_fail (retval, FALSE); - - while (ibus_message_iter_get_arg_type (&subsrc) != G_TYPE_INVALID) { - retval = ibus_message_iter_copy_data (&subdst, &subsrc); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (&subsrc); - } - - retval = ibus_message_iter_close_container (dst, &subdst); - g_return_val_if_fail (retval, FALSE); - - return TRUE; - } - else if (type == IBUS_TYPE_STRUCT) { - IBusMessageIter subdst, subsrc; - - retval = ibus_message_iter_recurse (src, IBUS_TYPE_STRUCT, &subsrc); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_open_container (dst, - IBUS_TYPE_STRUCT, - NULL, - &subdst); - g_return_val_if_fail (retval, FALSE); - - while (ibus_message_iter_get_arg_type (&subsrc) != G_TYPE_INVALID) { - retval = ibus_message_iter_copy_data (&subdst, &subsrc); - ibus_message_iter_next (&subsrc); - g_return_val_if_fail (retval, FALSE); - } - - retval = ibus_message_iter_close_container (dst, &subdst); - g_return_val_if_fail (retval, FALSE); - - return TRUE; - } - else if (type == IBUS_TYPE_DICT_ENTRY) { - IBusMessageIter subdst, subsrc; - - retval = ibus_message_iter_recurse (src, IBUS_TYPE_DICT_ENTRY, &subsrc); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_open_container (dst, - IBUS_TYPE_DICT_ENTRY, - NULL, - &subdst); - g_return_val_if_fail (retval, FALSE); - - /* copy key */ - retval = ibus_message_iter_copy_data (&subdst, &subsrc); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (&subsrc); - - /* copy value */ - retval = ibus_message_iter_copy_data (&subdst, &subsrc); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (&subsrc); - - retval = ibus_message_iter_close_container (dst, &subdst); - g_return_val_if_fail (retval, FALSE); - - return TRUE; - } - - return FALSE; - -} - -gboolean -ibus_message_iter_init (IBusMessage *message, - IBusMessageIter *iter) -{ - return dbus_message_iter_init (message, iter); -} - -void -ibus_message_iter_get_basic (IBusMessageIter *iter, - gpointer value) -{ - dbus_message_iter_get_basic (iter, value); -} - -gboolean -ibus_message_iter_get (IBusMessageIter *iter, - GType type, - gpointer value) -{ - g_assert (iter != NULL); - g_assert (type != G_TYPE_INVALID); - g_assert (value != NULL); - - switch (type) { - case G_TYPE_CHAR: - { - char v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_BYTE) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(gchar *) value = (gchar) v; - return TRUE; - } - case G_TYPE_INT: - { - dbus_int32_t v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INT32) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(gint *) value = (gint) v; - return TRUE; - } - case G_TYPE_UINT: - { - dbus_uint32_t v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_UINT32) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(guint *) value = (guint) v; - return TRUE; - } - case G_TYPE_LONG: - { - dbus_int64_t v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INT32) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(glong *) value = (glong) v; - return TRUE; - } - case G_TYPE_ULONG: - { - dbus_uint64_t v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_UINT32) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(gulong *) value = (gulong) v; - return TRUE; - } - - case G_TYPE_BOOLEAN: - { - dbus_bool_t v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_BOOLEAN) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(gboolean *) value = (gboolean) v; - return TRUE; - } - case G_TYPE_STRING: - { - gchar *v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_STRING) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(gchar **) value = (gchar *) v; - return TRUE; - } - case G_TYPE_INT64: - { - dbus_int64_t v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INT64) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(gint64 *) value = (gint64) v; - return TRUE; - } - case G_TYPE_UINT64: - { - dbus_uint64_t v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_UINT64) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(guint64 *) value = (guint64) v; - return TRUE; - } - case G_TYPE_FLOAT: - { - double v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_DOUBLE) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(gfloat *) value = (gfloat) v; - return TRUE; - } - - case G_TYPE_DOUBLE: - { - double v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_DOUBLE) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(gdouble *) value = (gdouble) v; - return TRUE; - } - default: - if (type == G_TYPE_VALUE) { - _from_dbus_value (iter, (GValue *) value); - return TRUE; - } - if (type == IBUS_TYPE_OBJECT_PATH) { - gchar *v; - if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_OBJECT_PATH) - return FALSE; - dbus_message_iter_get_basic (iter, &v); - *(gchar **) value = (gchar *) v; - return TRUE; - } - - if (g_type_is_a (type, IBUS_TYPE_SERIALIZABLE)) { - IBusSerializable *v; - v = ibus_serializable_deserialize (iter); - - if (v == NULL) - return FALSE; - if (!g_type_is_a (G_OBJECT_TYPE (v), type)) { - g_object_unref (v); - return FALSE; - } - *(gpointer *) value = v; - return TRUE; - } - } - return FALSE; -} - -gboolean -ibus_message_iter_next (IBusMessageIter *iter) -{ - return dbus_message_iter_next (iter); -} - -gboolean -ibus_message_iter_has_next (IBusMessageIter *iter) -{ - return dbus_message_iter_has_next (iter); -} - -gboolean -ibus_message_iter_open_container (IBusMessageIter *iter, - GType type, - const gchar *contained_signature, - IBusMessageIter *sub) -{ - gint dbus_type; - - if (type == IBUS_TYPE_ARRAY) { - dbus_type = DBUS_TYPE_ARRAY; - } - else if (type == IBUS_TYPE_STRUCT) { - dbus_type = DBUS_TYPE_STRUCT; - } - else if (type == IBUS_TYPE_DICT_ENTRY) { - dbus_type = DBUS_TYPE_DICT_ENTRY; - } - else if (type == IBUS_TYPE_VARIANT) { - dbus_type = DBUS_TYPE_VARIANT; - } - else - g_return_val_if_reached (FALSE); - - return dbus_message_iter_open_container (iter, - dbus_type, - contained_signature, - sub); -} - -gboolean -ibus_message_iter_close_container (IBusMessageIter *iter, - IBusMessageIter *sub) -{ - return dbus_message_iter_close_container (iter, sub); -} - - -static GType -dbus_type_to_gtype (gint type) -{ - switch (type) { -#define TYPE_TABLE(a, b) case a: return (b); - TYPE_TABLE (DBUS_TYPE_BYTE, G_TYPE_CHAR); - TYPE_TABLE (DBUS_TYPE_INT32, G_TYPE_INT); - TYPE_TABLE (DBUS_TYPE_INT64, G_TYPE_INT64); - TYPE_TABLE (DBUS_TYPE_UINT32, G_TYPE_UINT); - TYPE_TABLE (DBUS_TYPE_UINT64, G_TYPE_UINT64); - TYPE_TABLE (DBUS_TYPE_BOOLEAN, G_TYPE_BOOLEAN); - TYPE_TABLE (DBUS_TYPE_DOUBLE, G_TYPE_DOUBLE); - TYPE_TABLE (DBUS_TYPE_STRING, G_TYPE_STRING); - TYPE_TABLE (DBUS_TYPE_OBJECT_PATH, IBUS_TYPE_OBJECT_PATH); - TYPE_TABLE (DBUS_TYPE_ARRAY, IBUS_TYPE_ARRAY); - TYPE_TABLE (DBUS_TYPE_STRUCT, IBUS_TYPE_STRUCT); - TYPE_TABLE (DBUS_TYPE_DICT_ENTRY, IBUS_TYPE_DICT_ENTRY); - TYPE_TABLE (DBUS_TYPE_VARIANT, IBUS_TYPE_VARIANT); -#undef TYPE_TABLE - } - return G_TYPE_INVALID; -} - - -gboolean -ibus_message_iter_recurse (IBusMessageIter *iter, - GType type, - IBusMessageIter *sub) -{ - g_assert (iter != NULL); - g_assert (sub != NULL); - g_assert (type == IBUS_TYPE_ARRAY || - type == IBUS_TYPE_STRUCT || - type == IBUS_TYPE_DICT_ENTRY || - type == IBUS_TYPE_VARIANT); - GType gtype; - - gtype = ibus_message_iter_get_arg_type (iter); - - g_return_val_if_fail (gtype == type, FALSE); - - dbus_message_iter_recurse (iter, sub); - - return TRUE; -} - -GType -ibus_message_iter_get_arg_type (IBusMessageIter *iter) -{ - gint type; - - type = dbus_message_iter_get_arg_type (iter); - - return dbus_type_to_gtype (type); -} - - -GType -ibus_message_iter_get_element_type (IBusMessageIter *iter) -{ - gint type; - - type = dbus_message_iter_get_element_type (iter); - - return dbus_type_to_gtype (type); -} - -gchar * -ibus_message_to_string (IBusMessage *message) -{ - g_assert (message != NULL); - - GString *string = g_string_new (""); - - IBusMessageIter iter; - GType type; - gint i = 0; - - g_string_append_printf (string, - "message: %d\n" - "\tdestination = %s\n" - "\tpath = %s\n" - "\tinterface = %s\n" - "\tmember = %s\n", - ibus_message_get_type (message), - ibus_message_get_destination (message), - ibus_message_get_path (message), - ibus_message_get_interface (message), - ibus_message_get_member (message)); - - ibus_message_iter_init (message, &iter); - while ((type = ibus_message_iter_get_arg_type (&iter)) != G_TYPE_INVALID) { - g_string_append_printf (string, "\t\targ%d is %s\n", i++, g_type_name (type)); - ibus_message_iter_next (&iter); - } - - return g_string_free (string, FALSE); -} - diff --git a/src/ibusmessage.h b/src/ibusmessage.h deleted file mode 100644 index f4bdb3a..0000000 --- a/src/ibusmessage.h +++ /dev/null @@ -1,935 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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. - */ -/** - * SECTION: ibusmessage - * @Title: IBusMessage - * @Short_description: A DBusMessage in IBus. - * @Stability: Stable - * - * An IBusMessage is essentially a DBusMessage, which representing a message received from or to - * be sent to another application. - * - * Besides DBusMessage functions, An IBusMessage can be manipulated - * with its own specific functions, which are defined in this section. - */ -#ifndef __IBUS_MESSAGE_H_ -#define __IBUS_MESSAGE_H_ - -#include -#include -#include "ibusdbus.h" -#include "ibuserror.h" - -/** - * IBUS_TYPE_OBJECT_PATH: - * - * Type of object path. - */ -#define IBUS_TYPE_OBJECT_PATH (ibus_type_get_object_path ()) - -/** - * IBUS_TYPE_ARRAY: - * - * Type of IBusArray. - */ -#define IBUS_TYPE_ARRAY (ibus_type_get_array ()) - -/** - * IBUS_TYPE_STRUCT: - * - * Type of IBusStruct. - */ -#define IBUS_TYPE_STRUCT (ibus_type_get_struct ()) - -/** - * IBUS_TYPE_DICT_ENTRY: - * - * Type of IBusDictEntry. - */ -#define IBUS_TYPE_DICT_ENTRY (ibus_type_get_dict_entry ()) - -/** - * IBUS_TYPE_VARIANT: - * - * Type of IBusVariant. - */ -#define IBUS_TYPE_VARIANT (ibus_type_get_variant ()) - -G_BEGIN_DECLS - -/** - * ibus_type_get_object_path: - * @returns: Type of object path. - * - * Gets the type of object path. - */ -GType ibus_type_get_object_path (void); - -/** - * ibus_type_get_array: - * @returns: Type of IBusArray. - * - * Gets the type of IBusArray. - */ -GType ibus_type_get_array (void); - -/** - * ibus_type_get_struct: - * @returns: Type of IBusStruct. - * - * Gets the type of IBusStruct. - */ -GType ibus_type_get_struct (void); - -/** - * ibus_type_get_dict_entry: - * @returns: Type of IBusDictEntry. - * - * Gets the type of IBusDictEntry. - */ -GType ibus_type_get_dict_entry (void); - -/** - * ibus_type_get_variant: - * @returns: Type of IBusVariant. - * - * Gets the type of IBusVariant. - */ -GType ibus_type_get_variant (void); - -/** - * ibus_message_new: - * @message_type: Type of the message. - * @returns: A newly allocated IBusMessage according to @message_type. - * - * New an IBusMessage. - * Valid D-Bus message types include: - * - * - * #DBUS_MESSAGE_TYPE_METHOD_CALL - * - * - * #DBUS_MESSAGE_TYPE_METHOD_RETURN - * - * - * #DBUS_MESSAGE_TYPE_ERROR - * - * - * #DBUS_MESSAGE_TYPE_SIGNAL - * - * - * These are defined in dbus-protocol.h in D-Bus. - */ -IBusMessage *ibus_message_new (gint message_type); - -/** - * ibus_message_ref: - * @message: An IBusMessage. - * @returns: The IBusMessage. - * - * Increments the reference count of an IBusMessage. - */ -IBusMessage *ibus_message_ref (IBusMessage *message); - -/** - * ibus_message_unref: - * @message: An IBusMessage. - * - * Decrements the reference count of a DBusMessage, freeing the message if the count reaches 0. - */ -void ibus_message_unref (IBusMessage *message); - -/** - * ibus_message_new_method_call: - * @destination: Where this message to be sent to or %NULL for no destination. - * @path: Object path the message should be sent to. - * @interface: Interface to invoke method on, or %NULL. - * @method: The method to be invoked. - * @returns: A newly allocate IBusMessage; or %NULL if memory cannot be allocated. - * - * Constructs a new message to invoke a method on a remote object. - * - * The destination may be %NULL in which case no destination is set; - * this is appropriate when using IBus/D-Bus in a peer-to-peer context (no message bus). - * The interface may be %NULL, which means that if multiple methods with the given name - * exist it is undefined which one will be invoked. - * - * The path and method names may not be %NULL. - * - * Destination, path, interface, and method name can't contain any invalid characters - * (see the D-Bus specification). - */ -IBusMessage *ibus_message_new_method_call (const gchar *destination, - const gchar *path, - const gchar *interface, - const gchar *method); - -/** - * ibus_message_new_method_return: - * @reply_to: The IBusMessage being replied to. - * @returns: A newly allocate IBusMessage; or %NULL if memory cannot be allocated. - * - * Constructs a message that is a reply to a method call. - */ -IBusMessage *ibus_message_new_method_return (IBusMessage *reply_to); - -/** - * ibus_message_new_error: - * @reply_to: The IBusMessage being replied to. - * @error_name: Name of the error. - * @error_message: Detailed error message string (or %NULL for none, but please give a message). - * @returns: A newly allocate IBusMessage with the error information; or %NULL if memory cannot be allocated. - * - * Creates a new message that is an error reply to another message. - * Error replies are most common in response to method calls, but can be returned in reply to any message. - * The error name must be a valid error name according to the syntax given in the D-Bus specification. - * If you don't want to make up an error name just use %DBUS_ERROR_FAILED. - * - * Use ibus_message_unref() to free the produced IBusMessage. - */ -IBusMessage *ibus_message_new_error (IBusMessage *reply_to, - const gchar *error_name, - const gchar *error_message); - -/** - * ibus_message_new_error_printf: - * @reply_to: The IBusMessage being replied to. - * @error_name: Name of the error. - * @error_format: Error format string as in printf() format. - * @...: Format arguments, as in printf(). - * @returns: A newly allocate IBusMessage with the error information; or %NULL if memory cannot be allocated. - * - * Creates a new message that is an error reply to another message. - * Error replies are most common in response to method calls, but can be returned in reply to any message. - * The error name must be a valid error name according to the syntax given in the D-Bus specification. - * If you don't want to make up an error name just use %DBUS_ERROR_FAILED. - */ -IBusMessage *ibus_message_new_error_printf (IBusMessage *reply_to, - const gchar *error_name, - const gchar *error_format, - ...); - -/** - * ibus_message_new_signal: - * @path: Object path the message should be sent to. - * @interface: Interface to invoke method on, or %NULL. - * @method: The method to invoke. - * @returns: A newly allocate IBusMessage with the error information; or %NULL if memory cannot be allocated. - * - * Constructs a new message representing a signal emission. - * Returns NULL if memory can't be allocated for the message. - * A signal is identified by its originating object path, interface, and the name of the signal. - * Path, interface, and signal name must all be valid (the D-Bus specification defines the syntax of these fields). - */ -IBusMessage *ibus_message_new_signal (const gchar *path, - const gchar *interface, - const gchar *method); - -/** - * ibus_message_is_method_call: - * @message: An IBusMessage. - * @interface: The interface to check. Cannot be %NULL. - * @method: The method to check. Cannot be %NULL. - * @returns: %TRUE if @message is DBUS_MESSAGE_TYPE_METHOD_CALL and the invoked method is matched with @method; - * %FALSE otherwise. - * - * Checks whether the message is a method call with the given interface and member fields. - * - * If the message is not DBUS_MESSAGE_TYPE_METHOD_CALL, - * or has a different interface or member field, returns FALSE. - * If the interface field is missing, then it will be assumed equal to the provided interface. - * The D-Bus protocol allows method callers to leave out the interface name. - */ -gboolean ibus_message_is_method_call (IBusMessage *message, - const gchar *interface, - const gchar *method); -/** - * ibus_message_is_error: - * @message: An IBusMessage. - * @error_name: Name of the error to check. - * @returns: %TRUE if @message is DBUS_MESSAGE_TYPE_ERROR and the error name is matched with @error_name; - * %FALSE otherwise. - * - * Checks whether the message is an error reply with the given error name. - * If the message is not DBUS_MESSAGE_TYPE_ERROR, or has a different name, returns FALSE. - */ -gboolean ibus_message_is_error (IBusMessage *message, - const gchar *error_name); - -/** - * ibus_message_is_signal: - * @message: An IBusMessage. - * @interface: The interface to checked. Cannot be %NULL. - * @signal_name: The signal name to check. - * @returns: %TRUE if @message is %DBUS_MESSAGE_SIGNAL and the signal name is matched with @signal_name; - * %FALSE otherwise. - * - * Checks whether the message is a signal with the given interface and member fields. - * If the message is not %DBUS_MESSAGE_TYPE_SIGNAL, or has a different interface or member field, returns %FALSE. - */ -gboolean ibus_message_is_signal (IBusMessage *message, - const gchar *interface, - const gchar *signal_name); - -/** - * ibus_message_set_destination: - * @message: An IBusMessage. - * @destination: Destination to set; or %NULL to unset. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Sets the message's destination. - * - * The destination is the name of another connection on the bus - * and may be either the unique name assigned by the bus to each connection, - * or a well-known name specified in advance. - * - * The destination name must contain only valid characters as defined in the D-Bus specification. - */ -gboolean ibus_message_set_destination (IBusMessage *message, - const gchar *destination); -/** - * ibus_message_set_sender: - * @message: An IBusMessage. - * @sender: Sender to set; or %NULL to unset. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Sets the message sender. - * - * The sender must be a valid bus name as defined in the D-Bus specification. - * - * Usually you don't want to call this. The message bus daemon will call it to set the origin of each message. - * If you aren't implementing a message bus daemon you shouldn't need to set the sender. - */ -gboolean ibus_message_set_sender (IBusMessage *message, - const gchar *sender); - -/** - * ibus_message_set_error_name: - * @message: An IBusMessage. - * @error_name: Error name to set; or %NULL to unset. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Sets the name of the error (%DBUS_MESSAGE_TYPE_ERROR). - * - * The name is fully-qualified (namespaced). - * - * The error name must contain only valid characters as defined in the D-Bus specification. - */ -gboolean ibus_message_set_error_name (IBusMessage *message, - const gchar *error_name); - -/** - * ibus_message_set_interface: - * @message: An IBusMessage. - * @interface: Interface to set; or %NULL to unset. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Sets the interface this message is being sent to - * (for %DBUS_MESSAGE_TYPE_METHOD_CALL) or the interface - * a signal is being emitted from (for %DBUS_MESSAGE_TYPE_SIGNAL). - * - * The interface name must contain only valid characters as defined in the D-Bus specification. - */ -gboolean ibus_message_set_interface (IBusMessage *message, - const gchar *interface); - -/** - * ibus_message_set_member: - * @message: An IBusMessage. - * @member: Member to set; or %NULL to unset. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Sets the interface member being invoked (%DBUS_MESSAGE_TYPE_METHOD_CALL) - * or emitted (%DBUS_MESSAGE_TYPE_SIGNAL). - * - * The member name must contain only valid characters as defined in the D-Bus specification. - */ -gboolean ibus_message_set_member (IBusMessage *message, - const gchar *member); - -/** - * ibus_message_set_path: - * @message: An IBusMessage. - * @path: Path to set; or %NULL to unset. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Sets the object path this message is being sent to (for $DBUS_MESSAGE_TYPE_METHOD_CALL) - * or the one a signal is being emitted from (for %DBUS_MESSAGE_TYPE_SIGNAL). - * - * The path must contain only valid characters as defined in the D-Bus specification. - */ -gboolean ibus_message_set_path (IBusMessage *message, - const gchar *path); - -/** - * ibus_message_set_no_reply: - * @message: An IBusMessage. - * @no_reply: %TRUE if no reply is desired. - * - * Sets a flag indicating that the message does not want a reply; - * if this flag is set, the other end of the connection may (but is not required to) - * optimize by not sending method return or error replies. - * - * If this flag is set, there is no way to know whether the message successfully arrived - * at the remote end. - * Normally you know a message was received when you receive the reply to it. - * - * The flag is FALSE by default, that is by default the other end is required to reply. - * - * On the protocol level this toggles %DBUS_HEADER_FLAG_NO_REPLY_EXPECTED. - */ -void ibus_message_set_no_reply (IBusMessage *message, - gboolean no_reply); - -/** - * ibus_message_set_reply_serial: - * @message: An IBusMessage. - * @reply_serial: The serial to be replied. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Sets the reply serial of a message (the serial of the message this is a reply to). - */ -gboolean ibus_message_set_reply_serial (IBusMessage *message, - guint32 reply_serial); - -/** - * ibus_message_get_type: - * @message: An IBusMessage. - * @returns: Type of the IBusMessage. - * - * Gets the type of an IBusMessage. - */ -gint ibus_message_get_type (IBusMessage *message); - -/** - * ibus_message_get_destination: - * @message: An IBusMessage. - * @returns: Destination of the IBusMessage; NULL if there is none set. - * - * Gets the destination of a message or %NULL if there is none set. - * - * The returned string becomes invalid if the message is modified, - * since it points into the wire-marshaled message data. - */ -const gchar *ibus_message_get_destination (IBusMessage *message); - -/** - * ibus_message_get_sender: - * @message: An IBusMessage. - * @returns: Sender of the IBusMessage; %NULL if unknown or inapplicable. - * - * Gets the unique name of the connection which originated this message, - * or %NULL if unknown or inapplicable. - * - * The sender is filled in by the message bus. - * - * Note, the returned sender is always the unique bus name. - * Connections may own multiple other bus names, but those are not found in the sender field. - * - * The returned string becomes invalid if the message is modified, - * since it points into the wire-marshaled message data. - */ -const gchar *ibus_message_get_sender (IBusMessage *message); - -/** - * ibus_message_get_error_name: - * @message: An IBusMessage. - * @returns: Error name of the IBusMessage; %NULL if none. - * - * Gets the error name (%DBUS_MESSAGE_TYPE_ERROR only) or %NULL if none. - * - * The returned string becomes invalid if the message is modified, - * since it points into the wire-marshaled message data. - */ -const gchar *ibus_message_get_error_name (IBusMessage *message); - -/** - * ibus_message_get_error_message: - * @message: An IBusMessage. - * @returns: Error message of the IBusMessage; %NULL if none. - * - * Gets the error message (%DBUS_MESSAGE_TYPE_ERROR only) or %NULL if none. - * - * The returned string becomes invalid if the message is modified, - * since it points into the wire-marshaled message data. - */ -const gchar *ibus_message_get_error_message (IBusMessage *message); - -/** - * ibus_message_get_interface: - * @message: An IBusMessage. - * @returns: Interface name of the IBusMessage; %NULL if none. - * - * Gets the interface this message is being sent to (for %DBUS_MESSAGE_TYPE_METHOD_CALL) - * or being emitted from (for %DBUS_MESSAGE_TYPE_SIGNAL). - * - * The interface name is fully-qualified (namespaced). Returns %NULL if none. - * - * The returned string becomes invalid if the message is modified, - * since it points into the wire-marshaled message data. - */ -const gchar *ibus_message_get_interface (IBusMessage *message); - -/** - * ibus_message_get_member: - * @message: An IBusMessage. - * @returns: Member name of the IBusMessage; %NULL if none. - * - * Gets the interface member being invoked (%DBUS_MESSAGE_TYPE_METHOD_CALL) - * or emitted (%DBUS_MESSAGE_TYPE_SIGNAL). - * - * Returns %NULL if none. - * - * The returned string becomes invalid if the message is modified, - * since it points into the wire-marshaled message data. - */ -const gchar *ibus_message_get_member (IBusMessage *message); - -/** - * ibus_message_get_path: - * @message: An IBusMessage. - * @returns: Object path of the IBusMessage; %NULL if none. - * - * Gets the object path this message is being sent to (for %DBUS_MESSAGE_TYPE_METHOD_CALL) - * or being emitted from (for %DBUS_MESSAGE_TYPE_SIGNAL). - * - * Returns %NULL if none. - * - * See also dbus_message_get_path_decomposed(). - * - * The returned string becomes invalid if the message is modified, - * since it points into the wire-marshaled message data. - */ -const gchar *ibus_message_get_path (IBusMessage *message); - -/** - * ibus_message_get_no_reply: - * @message: An IBusMessage. - * @returns: %TRUE if the message does not expect a reply; %FALSE otherwise. - * - * Returns TRUE if the message does not expect a reply. - */ -gboolean ibus_message_get_no_reply (IBusMessage *message); - -/** - * ibus_message_get_reply_serial: - * @message: An IBusMessage. - * @returns: The serial that the message is a reply to or 0 if none. - * - * Returns the serial that the message is a reply to or 0 if none. - */ -guint32 ibus_message_get_reply_serial (IBusMessage *message); - -/** - * ibus_message_get_serial: - * @message: An IBusMessage. - * @returns: The serial of a message or 0 if none has been specified. - * - * Returns the serial of a message or 0 if none has been specified. - * - * The message's serial number is provided by the application sending the message - * and is used to identify replies to this message. - * - * All messages received on a connection will have a serial provided by the remote application. - * - * For messages you're sending, dbus_connection_send() will assign a serial and return it to you. - */ -guint32 ibus_message_get_serial (IBusMessage *message); - -/** - * ibus_message_append_args: - * @message: An IBusMessage. - * @first_arg_type: Type of the first argument. - * @...: Rest of arguments. - * @returns: %TRUE if succeed; %FALSE otherwise. - * - * Appends fields to a message given a variable argument list. - * - * The variable argument list should contain the type of each argument followed by the value to append. - * Appendable types are basic types, and arrays of fixed-length basic types. - * To append variable-length basic types, or any more complex value, - * you have to use an iterator rather than this function. - * - * To append a basic type, specify its type code followed by the address of the value. For example: - * - * - * dbus_int32_t v_INT32 = 42; - * const char *v_STRING = "Hello World"; - * dbus_message_append_args (message, - * DBUS_TYPE_INT32, &v_INT32, - * DBUS_TYPE_STRING, &v_STRING, - * DBUS_TYPE_INVALID); - * - * - * - * To append an array of fixed-length basic types, pass in the %DBUS_TYPE_ARRAY typecode, - * the element typecode, the address of the array pointer, - * and a 32-bit integer giving the number of elements in the array. So for example: - * - * - * const dbus_int32_t array[] = { 1, 2, 3 }; - * const dbus_int32_t *v_ARRAY = array; - * dbus_message_append_args (message, - * DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &v_ARRAY, 3, - * DBUS_TYPE_INVALID); - * - * - * - * - * - * in C, given "int array[]", "&array == array" (the comp.lang.c FAQ says otherwise, but gcc and the FAQ don't agree). - * So if you're using an array instead of a pointer you have to create a pointer variable, - * assign the array to it, then take the address of the pointer variable. - * For strings it works to write const char *array = "Hello" and then use &array though. - * - * - * The last argument to this function must be %DBUS_TYPE_INVALID, marking the end of the argument list. - * If you don't do this then libdbus won't know to stop and will read invalid memory. - * - * String/signature/path arrays should be passed in as "const char*** address_of_array" and "int n_elements" - * - * @see_also: ibus_message_append_args_valist(). - */ -gboolean ibus_message_append_args (IBusMessage *message, - GType first_arg_type, - ...); - -/** - * ibus_message_append_args_valist: - * @message: An IBusMessage. - * @first_arg_type: Type of the first argument. - * @va_args: Rest of arguments. - * @returns: %TRUE if succeed; %FALSE otherwise. - * - * Like ibus_message_append_args() but takes a va_list for use by language bindings. - * - * @see_also: ibus_message_append_args(). - */ -gboolean ibus_message_append_args_valist(IBusMessage *message, - GType first_arg_type, - va_list va_args); - -/** - * ibus_message_get_args: - * @message: An IBusMessage. - * @error: Error to be filled in on failure. - * @first_arg_type: Type of the first argument. - * @...: Rest of arguments. - * @returns: %TRUE if succeed; F%ALSE otherwise. - * - * Gets arguments from a message given a variable argument list. - * - * The supported types include those supported by ibus_message_append_args(); - * that is, basic types and arrays of fixed-length basic types. - * The arguments are the same as they would be for ibus_message_iter_get_basic() - * or ibus_message_iter_get_fixed_array(). - * - * In addition to those types, arrays of string, object path, and signature are supported; - * but these are returned as allocated memory and must be freed with dbus_free_string_array(), - * while the other types are returned as const references. - * To get a string array pass in "char ***array_location" and "int *n_elements". - * - * The variable argument list should contain the type of the argument followed by a pointer to - * where the value should be stored. The list is terminated with %DBUS_TYPE_INVALID. - * - * Except for string arrays, the returned values are constant; do not free them. - * They point into the IBusMessage. - * - * If the requested arguments are not present, or do not have the requested types, then an error will be set. - * - * If more arguments than requested are present, - * the requested arguments are returned and the extra arguments are ignored. - * - * @see_also: ibus_message_append_args(), ibus_message_get_args_valist(). - */ -gboolean ibus_message_get_args (IBusMessage *message, - IBusError **error, - GType first_arg_type, - ...); - -/** - * ibus_message_get_args_valist: - * @message: An IBusMessage. - * @error: Error message is outputted here; or %NULL to suppress error. - * @first_arg_type: Type of the first argument. - * @va_args: Rest of arguments. - * @returns: %TRUE if succeed; %FALSE otherwise. - * - * Like ibus_message_get_args but takes a va_list for use by language bindings. - * - * @see_also: ibus_message_append_args_valist(), ibus_message_get_args(). - */ -gboolean ibus_message_get_args_valist (IBusMessage *message, - IBusError **error, - GType first_arg_type, - va_list va_args); - -/** - * ibus_message_iter_init_append: - * @message: An IBusMessage. - * @iter: An IBusMessageIter to to initialize. - * - * Initializes a #IBusMessageIter for appending arguments to the end of a message. - */ -void ibus_message_iter_init_append (IBusMessage *message, - IBusMessageIter *iter); -/** - * ibus_message_iter_append: - * @iter: An IBusMessageIter. - * @type: The type of the value. - * @value: The pointer to the value. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Appends a basic-typed value to the message. - * - * The basic types are the non-container types such as integer and string. - * - * The "value" argument should be the address of a basic-typed value. - * So for string, const char**. For integer, dbus_int32_t*. - */ -gboolean ibus_message_iter_append (IBusMessageIter *iter, - GType type, - gconstpointer value); - -/** - * ibus_message_iter_copy_data: - * @dst: Destination to be copy to. - * @src: Source to be copy from. - * @returns: %TRUE if succeed; %FALSE if failed. - * - * Deep copy an IBusMessageIter to another IBusMessageIter. - * - * Since: 1.2.0.20090719 - */ -gboolean ibus_message_iter_copy_data (IBusMessageIter *dst, - IBusMessageIter *src); - -/** - * ibus_message_iter_init: - * @message: An IBusMessage. - * @iter: An IBusMessageIter. - * @returns: %TRUE if succeed; %FALSE if the message has no arguments. - * - * Initializes an #IBusMessageIter for reading the arguments of the message passed in. - * - * When possible, ibus_message_get_args() is much more convenient. - * Some types of argument can only be read with IBusMessageIter however. - * - * The easiest way to iterate is like this: - * - * - * dbus_message_iter_init (&iter); - * while ((current_type = dbus_message_iter_get_arg_type (&iter)) != DBUS_TYPE_INVALID) - * dbus_message_iter_next (&iter); - * - * - * - * IBusMessageIter contains no allocated memory; - * it need not be freed, and can be copied by assignment or memcpy(). - */ -gboolean ibus_message_iter_init (IBusMessage *message, - IBusMessageIter *iter); - -/** - * ibus_message_iter_get_basic: - * @iter: An IBusMessageIter. - * @value: Result value stores here. Cannot be %NULL. - * - * Reads a basic-typed value from the message iterator. - * - * Basic types are the non-containers such as integer and string. - * - * The value argument should be the address of a location to store the returned value. - * So for int32 it should be a "dbus_int32_t*" and for string a "const char**". - * The returned value is by reference and should not be freed. - * - * Be sure you have somehow checked that dbus_message_iter_get_arg_type() matches the type you are expecting, - * or you'll crash when you try to use an integer as a string or something. - * - * To read any container type (array, struct, dict) you will need to recurse into the container with - * dbus_message_iter_recurse(). - * If the container is an array of fixed-length values, - * you can get all the array elements at once with dbus_message_iter_get_fixed_array(). - * Otherwise, you have to iterate over the container's contents one value at a time. - * - * All basic-typed values are guaranteed to fit in 8 bytes. So you can write code like this: - * - * - * dbus_uint64_t value; - * int type; - * dbus_message_iter_get_basic (&read_iter, &value); - * type = dbus_message_iter_get_arg_type (&read_iter); - * dbus_message_iter_append_basic (&write_iter, type, &value); - * - * - * - * On some really obscure platforms dbus_uint64_t might not exist, - * if you need to worry about this you will know. - * dbus_uint64_t is just one example of a type that's large enough to hold any possible value, - * you could use a struct or char[8] instead if you like. - */ -void ibus_message_iter_get_basic (IBusMessageIter *iter, - gpointer value); - -/** - * ibus_message_iter_get: - * @iter: An IBusMessageIter. - * @type: The type of the value. Cannot be %NULL. - * @value: Result value stores here. Cannot be %NULL. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Gets an value from an IBusMessageIter, then move on to the next element. - * - */ -gboolean ibus_message_iter_get (IBusMessageIter *iter, - GType type, - gpointer value); - -/** - * ibus_message_iter_next: - * @iter: An IBusMessageIter. - * @returns: %TRUE if the iterator moves forward successfully; %FALSE if next element does not exist. - * - * Moves the iterator to the next field, if any. - * - * If there's no next field, returns %FALSE. If the iterator moves forward, returns %TRUE. - */ -gboolean ibus_message_iter_next (IBusMessageIter *iter); - -/** - * ibus_message_iter_has_next: - * @iter: An IBusMessageIter. - * @returns: %TRUE if next element exists; %FALSE otherwise. - * - * Checks if an iterator has any more fields. - */ -gboolean ibus_message_iter_has_next (IBusMessageIter *iter); - -/** - * ibus_message_iter_open_container: - * @iter: An IBusMessageIter. - * @type: The type of the value. - * @contained_signature: The type of container contents. - * @sub: Sub-iterator to initialize. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Appends a container-typed value to the message; - * you are required to append the contents of the container using the returned sub-iterator, - * and then call dbus_message_iter_close_container(). - * - * Container types are for example struct, variant, and array. - * For variants, the contained_signature should be the type of the single value inside the variant. - * For structs and dict entries, contained_signature should be %NULL; - * it will be set to whatever types you write into the struct. - * For arrays, contained_signature should be the type of the array elements. - */ -gboolean ibus_message_iter_open_container - (IBusMessageIter *iter, - GType type, - const gchar *contained_signature, - IBusMessageIter *sub); - -/** - * ibus_message_iter_close_container: - * @iter: An IBusMessageIter. - * @sub: Sub-iterator to close. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Closes a container-typed value appended to the message; - * may write out more information to the message known only after the entire container is written, - * and may free resources created by dbus_message_iter_open_container(). - */ -gboolean ibus_message_iter_close_container - (IBusMessageIter *iter, - IBusMessageIter *sub); - -/** - * ibus_message_iter_recurse: - * @iter: An IBusMessageIter. - * @type: The type of the value. - * @sub: Sub-iterator to initialize. - * @returns: %TRUE if succeed; %FALSE if insufficient memory. - * - * Recurses into a container value when reading values from a message, - * initializing a sub-iterator to use for traversing the child values of the container. - * - * Note that this recurses into a value, not a type, so you can only recurse if the value exists. - * The main implication of this is that if you have for example an empty array of array of int32, - * you can recurse into the outermost array, but it will have no values, so you won't be able to recurse further. - * There's no array of int32 to recurse into. - * - * If a container is an array of fixed-length types, it is much more efficient to use - * dbus_message_iter_get_fixed_array() to get the whole array in one shot, - * rather than individually walking over the array elements. - * - * Be sure you have somehow checked that dbus_message_iter_get_arg_type() - * matches the type you are expecting to recurse into. - * Results of this function are undefined if there is no container to recurse into at the current iterator position. - */ -gboolean ibus_message_iter_recurse (IBusMessageIter *iter, - GType type, - IBusMessageIter *sub); - -/** - * ibus_message_iter_get_arg_type: - * @iter: An IBusMessageIter. - * @returns: The argument type. - * - * Returns the argument type of the argument that the message iterator points to. - * - * If the iterator is at the end of the message, returns %DBUS_TYPE_INVALID. - * You can thus write a loop as follows: - * - * - * dbus_message_iter_init (&iter); - * while ((current_type = dbus_message_iter_get_arg_type (&iter)) != DBUS_TYPE_INVALID) - * dbus_message_iter_next (&iter); - * - * - */ -GType ibus_message_iter_get_arg_type (IBusMessageIter *iter); - -/** - * ibus_message_iter_get_element_type: - * @iter: An IBusMessageIter. - * @returns: The argument type. - * - * Returns the element type of the array that the message iterator points to. - * Note that you need to check that the iterator points to an array prior to using this function. - */ -GType ibus_message_iter_get_element_type - (IBusMessageIter *iter); - -/** - * ibus_message_to_string: - * @message: An IBusMessage. - * @returns: A string which shows the information of the message. - * - * Produces a pretty formatted string which show the information of the IBusMessage. - * This string is suitable for debugging information print out. - * - * Free the string by g_free() after use. - */ -gchar *ibus_message_to_string (IBusMessage *message); - -G_END_DECLS -#endif diff --git a/src/ibusobject.c b/src/ibusobject.c index 515dec0..12a4fb0 100644 --- a/src/ibusobject.c +++ b/src/ibusobject.c @@ -21,6 +21,7 @@ */ #include "ibusobject.h" +#include "ibusmarshalers.h" #include "ibusinternal.h" #define IBUS_OBJECT_GET_PRIVATE(o) \ @@ -31,7 +32,6 @@ enum { LAST_SIGNAL, }; -typedef struct _IBusObjectPrivate IBusObjectPrivate; struct _IBusObjectPrivate { gpointer pad; }; @@ -55,31 +55,16 @@ static void ibus_object_real_destroy (IBusObject *obj); G_DEFINE_TYPE (IBusObject, ibus_object, G_TYPE_INITIALLY_UNOWNED) -/** - * ibus_object_new: - * - * Creates a new instance of an #IBusObject. - * - * Returns: a new instance of #IBusObject. - */ -IBusObject * -ibus_object_new (void) -{ - return IBUS_OBJECT (g_object_new (IBUS_TYPE_OBJECT, NULL)); -} - static void -ibus_object_class_init (IBusObjectClass *klass) +ibus_object_class_init (IBusObjectClass *class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IBusObjectPrivate)); + GObjectClass *gobject_class = G_OBJECT_CLASS (class); gobject_class->constructor = ibus_object_constructor; gobject_class->dispose = (GObjectFinalizeFunc) ibus_object_dispose; gobject_class->finalize = (GObjectFinalizeFunc) ibus_object_finalize; - klass->destroy = ibus_object_real_destroy; + class->destroy = ibus_object_real_destroy; /* install signals */ /** @@ -98,22 +83,21 @@ ibus_object_class_init (IBusObjectClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusObjectClass, destroy), NULL, NULL, - ibus_marshal_VOID__VOID, + _ibus_marshal_VOID__VOID, G_TYPE_NONE, 0); + + g_type_class_add_private (class, sizeof (IBusObjectPrivate)); + #ifdef DEBUG_MEMORY _count_table = g_hash_table_new (g_direct_hash, g_direct_equal); #endif - } static void ibus_object_init (IBusObject *obj) { - IBusObjectPrivate *priv; - priv = IBUS_OBJECT_GET_PRIVATE (obj); - obj->flags = 0; - + obj->priv = IBUS_OBJECT_GET_PRIVATE (obj); } @@ -160,7 +144,7 @@ ibus_object_dispose (IBusObject *obj) static void ibus_object_finalize (IBusObject *obj) { -#ifdef DEBUG_MEMORY +#ifdef DEBUG_MEMORY guint count; _count --; @@ -178,11 +162,24 @@ ibus_object_real_destroy (IBusObject *obj) g_signal_handlers_destroy (obj); } +/** + * ibus_object_new: + * + * Creates a new instance of an #IBusObject. + * + * Returns: a new instance of #IBusObject. + */ +IBusObject * +ibus_object_new (void) +{ + GObject *object = g_object_new (IBUS_TYPE_OBJECT, NULL); + return IBUS_OBJECT (object); +} + void ibus_object_destroy (IBusObject *obj) { - IBusObjectPrivate *priv; - priv = IBUS_OBJECT_GET_PRIVATE (obj); + g_return_if_fail (IBUS_IS_OBJECT (obj)); if (! (IBUS_OBJECT_FLAGS (obj) & IBUS_IN_DESTRUCTION)) { g_object_run_dispose (G_OBJECT (obj)); diff --git a/src/ibusobject.h b/src/ibusobject.h index cc6cce4..9663022 100644 --- a/src/ibusobject.h +++ b/src/ibusobject.h @@ -19,6 +19,11 @@ * 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: ibusobject * @short_description: Base object of IBus. @@ -31,7 +36,6 @@ #define __IBUS_OBJECT_H_ #include -#include "ibusmarshalers.h" #include "ibustypes.h" #include "ibusdebug.h" @@ -69,6 +73,8 @@ G_BEGIN_DECLS typedef struct _IBusObject IBusObject; typedef struct _IBusObjectClass IBusObjectClass; +typedef struct _IBusObjectPrivate IBusObjectPrivate; + /** * IBusObject: * @@ -76,9 +82,11 @@ typedef struct _IBusObjectClass IBusObjectClass; * private to the #IBusObject and should never be accessed directly. */ struct _IBusObject { - GInitiallyUnowned parent; - /* instance members */ - guint32 flags; + GInitiallyUnowned parent; + /* instance members */ + guint32 flags; + + IBusObjectPrivate *priv; }; typedef void ( *IBusObjectDestroyFunc) (IBusObject *); diff --git a/src/ibusobservedpath.c b/src/ibusobservedpath.c index 7086a81..b3b82a0 100644 --- a/src/ibusobservedpath.c +++ b/src/ibusobservedpath.c @@ -43,9 +43,9 @@ typedef struct _IBusObservedPathPrivate IBusObservedPathPrivate; /* functions prototype */ static void ibus_observed_path_destroy (IBusObservedPath *path); static gboolean ibus_observed_path_serialize (IBusObservedPath *path, - IBusMessageIter *iter); -static gboolean ibus_observed_path_deserialize (IBusObservedPath *path, - IBusMessageIter *iter); + GVariantBuilder *builder); +static gint ibus_observed_path_deserialize (IBusObservedPath *path, + GVariant *variant); static gboolean ibus_observed_path_copy (IBusObservedPath *dest, const IBusObservedPath *src); static gboolean ibus_observed_path_parse_xml_node (IBusObservedPath *path, @@ -54,27 +54,24 @@ static gboolean ibus_observed_path_parse_xml_node (IBusObservedPath *pat G_DEFINE_TYPE (IBusObservedPath, ibus_observed_path, IBUS_TYPE_SERIALIZABLE) static void -ibus_observed_path_class_init (IBusObservedPathClass *klass) +ibus_observed_path_class_init (IBusObservedPathClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); - IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); + IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class); - // g_type_class_add_private (klass, sizeof (IBusObservedPathPrivate)); + // g_type_class_add_private (class, sizeof (IBusObservedPathPrivate)); object_class->destroy = (IBusObjectDestroyFunc) ibus_observed_path_destroy; serializable_class->serialize = (IBusSerializableSerializeFunc) ibus_observed_path_serialize; serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_observed_path_deserialize; serializable_class->copy = (IBusSerializableCopyFunc) ibus_observed_path_copy; - - g_string_append (serializable_class->signature, "sx"); } static void ibus_observed_path_init (IBusObservedPath *path) { - path->path = NULL; } static void @@ -86,42 +83,32 @@ ibus_observed_path_destroy (IBusObservedPath *path) static gboolean ibus_observed_path_serialize (IBusObservedPath *path, - IBusMessageIter *iter) + GVariantBuilder *builder) { gboolean retval; - retval = IBUS_SERIALIZABLE_CLASS (ibus_observed_path_parent_class)->serialize ((IBusSerializable *)path, iter); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &(path->path)); + retval = IBUS_SERIALIZABLE_CLASS (ibus_observed_path_parent_class)->serialize ((IBusSerializable *)path, builder); g_return_val_if_fail (retval, FALSE); - retval = ibus_message_iter_append (iter, G_TYPE_LONG, &(path->mtime)); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "s", path->path); + g_variant_builder_add (builder, "x", path->mtime); return TRUE; } -static gboolean +static gint ibus_observed_path_deserialize (IBusObservedPath *path, - IBusMessageIter *iter) + GVariant *variant) { - gboolean retval; - gchar *str; + gint retval; - retval = IBUS_SERIALIZABLE_CLASS (ibus_observed_path_parent_class)->deserialize ((IBusSerializable *)path, iter); - g_return_val_if_fail (retval, FALSE); + retval = IBUS_SERIALIZABLE_CLASS (ibus_observed_path_parent_class)->deserialize ((IBusSerializable *)path, variant); + g_return_val_if_fail (retval, 0); - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - path->path = g_strdup (str); + g_variant_get_child (variant, retval++, "s", &path->path); + g_variant_get_child (variant, retval++, "x", &path->mtime); - retval = ibus_message_iter_get (iter, G_TYPE_LONG, &(path->mtime)); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - - return TRUE; + return retval; } static gboolean diff --git a/src/ibusobservedpath.h b/src/ibusobservedpath.h index 783999b..e0d7033 100644 --- a/src/ibusobservedpath.h +++ b/src/ibusobservedpath.h @@ -19,6 +19,11 @@ * 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: ibusobservedpath * @short_description: Path object of IBus. diff --git a/src/ibuspanelservice.c b/src/ibuspanelservice.c index 7afb0a5..bd24c9a 100644 --- a/src/ibuspanelservice.c +++ b/src/ibuspanelservice.c @@ -2,6 +2,7 @@ /* vim:set et sts=4: */ /* ibus - The Input Bus * Copyright (c) 2009, Google Inc. All rights reserved. + * Copyright (C) 2010 Peng Huang * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,118 +19,119 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include "ibusshare.h" #include "ibuspanelservice.h" enum { + LAST_SIGNAL, +}; + +enum { PROP_0, - PROP_CONNECTION, }; /* functions prototype */ -static void ibus_panel_service_service_set_property (IBusPanelService *panel, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void ibus_panel_service_service_get_property (IBusPanelService *panel, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void ibus_panel_service_real_destroy (IBusPanelService *panel); -static gboolean ibus_panel_service_ibus_message (IBusPanelService *panel, - IBusConnection *connection, - IBusMessage *message); -static gboolean ibus_panel_service_not_implemented (IBusPanelService *panel, - IBusError **error); -static gboolean ibus_panel_service_focus_in (IBusPanelService *panel, - const gchar *input_context_path, - IBusError **error); -static gboolean ibus_panel_service_focus_out (IBusPanelService *panel, - const gchar *input_context_path, - IBusError **error); -static gboolean ibus_panel_service_register_properties (IBusPanelService *panel, - IBusPropList *prop_list, - IBusError **error); -static gboolean ibus_panel_service_set_cursor_location (IBusPanelService *panel, - gint x, - gint y, - gint w, - gint h, - IBusError **error); -static gboolean ibus_panel_service_update_auxiliary_text (IBusPanelService *panel, - IBusText *text, - gboolean visible, - IBusError **error); -static gboolean ibus_panel_service_update_lookup_table (IBusPanelService *panel, - IBusLookupTable *lookup_table, - gboolean visible, - IBusError **error); -static gboolean ibus_panel_service_update_preedit_text (IBusPanelService *panel, - IBusText *text, - guint cursor_pos, - gboolean visible, - IBusError **error); -static gboolean ibus_panel_service_update_property (IBusPanelService *panel, - IBusProperty *prop, - IBusError **error); +static void ibus_panel_service_set_property (IBusPanelService *panel, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void ibus_panel_service_get_property (IBusPanelService *panel, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void ibus_panel_service_real_destroy (IBusPanelService *panel); +static void ibus_panel_service_service_method_call (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation); +static GVariant *ibus_panel_service_service_get_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error); +static gboolean ibus_panel_service_service_set_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error); +static void ibus_panel_service_not_implemented (IBusPanelService *panel); +static void ibus_panel_service_focus_in (IBusPanelService *panel, + const gchar *input_context_path); +static void ibus_panel_service_focus_out (IBusPanelService *panel, + const gchar *input_context_path); +static void ibus_panel_service_register_properties (IBusPanelService *panel, + IBusPropList *prop_list); +static void ibus_panel_service_set_cursor_location (IBusPanelService *panel, + gint x, + gint y, + gint w, + gint h); +static void ibus_panel_service_update_auxiliary_text (IBusPanelService *panel, + IBusText *text, + gboolean visible); +static void ibus_panel_service_update_lookup_table (IBusPanelService *panel, + IBusLookupTable *lookup_table, + gboolean visible); +static void ibus_panel_service_update_preedit_text (IBusPanelService *panel, + IBusText *text, + guint cursor_pos, + gboolean visible); +static void ibus_panel_service_update_property (IBusPanelService *panel, + IBusProperty *prop); G_DEFINE_TYPE (IBusPanelService, ibus_panel_service, IBUS_TYPE_SERVICE) -IBusPanelService * -ibus_panel_service_new (IBusConnection *connection) -{ - g_assert (IBUS_IS_CONNECTION (connection)); - - IBusPanelService *panel; - - panel = (IBusPanelService*) g_object_new (IBUS_TYPE_PANEL_SERVICE, - "path", IBUS_PATH_PANEL, - "connection", connection, - NULL); - - return panel; -} - static void -ibus_panel_service_class_init (IBusPanelServiceClass *klass) +ibus_panel_service_class_init (IBusPanelServiceClass *class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (class); - gobject_class->set_property = (GObjectSetPropertyFunc) ibus_panel_service_service_set_property; - gobject_class->get_property = (GObjectGetPropertyFunc) ibus_panel_service_service_get_property; + gobject_class->set_property = (GObjectSetPropertyFunc) ibus_panel_service_set_property; + gobject_class->get_property = (GObjectGetPropertyFunc) ibus_panel_service_get_property; IBUS_OBJECT_CLASS (gobject_class)->destroy = (IBusObjectDestroyFunc) ibus_panel_service_real_destroy; - IBUS_SERVICE_CLASS (klass)->ibus_message = (ServiceIBusMessageFunc) ibus_panel_service_ibus_message; - - klass->focus_in = ibus_panel_service_focus_in; - klass->focus_out = ibus_panel_service_focus_out; - klass->register_properties = ibus_panel_service_register_properties; - klass->set_cursor_location = ibus_panel_service_set_cursor_location; - klass->update_lookup_table = ibus_panel_service_update_lookup_table; - klass->update_auxiliary_text = ibus_panel_service_update_auxiliary_text; - klass->update_preedit_text = ibus_panel_service_update_preedit_text; - klass->update_property = ibus_panel_service_update_property; - - klass->cursor_down_lookup_table = ibus_panel_service_not_implemented; - klass->cursor_up_lookup_table = ibus_panel_service_not_implemented; - klass->destroy = ibus_panel_service_not_implemented; - klass->hide_auxiliary_text = ibus_panel_service_not_implemented; - klass->hide_language_bar = ibus_panel_service_not_implemented; - klass->hide_lookup_table = ibus_panel_service_not_implemented; - klass->hide_preedit_text = ibus_panel_service_not_implemented; - klass->page_down_lookup_table = ibus_panel_service_not_implemented; - klass->page_up_lookup_table = ibus_panel_service_not_implemented; - klass->reset = ibus_panel_service_not_implemented; - klass->show_auxiliary_text = ibus_panel_service_not_implemented; - klass->show_language_bar = ibus_panel_service_not_implemented; - klass->show_lookup_table = ibus_panel_service_not_implemented; - klass->show_preedit_text = ibus_panel_service_not_implemented; - klass->start_setup = ibus_panel_service_not_implemented; - klass->state_changed = ibus_panel_service_not_implemented; + IBUS_SERVICE_CLASS (class)->service_method_call = ibus_panel_service_service_method_call; + IBUS_SERVICE_CLASS (class)->service_get_property = ibus_panel_service_service_get_property; + IBUS_SERVICE_CLASS (class)->service_set_property = ibus_panel_service_service_set_property; + + class->focus_in = ibus_panel_service_focus_in; + class->focus_out = ibus_panel_service_focus_out; + class->register_properties = ibus_panel_service_register_properties; + class->set_cursor_location = ibus_panel_service_set_cursor_location; + class->update_lookup_table = ibus_panel_service_update_lookup_table; + class->update_auxiliary_text = ibus_panel_service_update_auxiliary_text; + class->update_preedit_text = ibus_panel_service_update_preedit_text; + class->update_property = ibus_panel_service_update_property; + + class->cursor_down_lookup_table = ibus_panel_service_not_implemented; + class->cursor_up_lookup_table = ibus_panel_service_not_implemented; + class->destroy = ibus_panel_service_not_implemented; + class->hide_auxiliary_text = ibus_panel_service_not_implemented; + class->hide_language_bar = ibus_panel_service_not_implemented; + class->hide_lookup_table = ibus_panel_service_not_implemented; + class->hide_preedit_text = ibus_panel_service_not_implemented; + class->page_down_lookup_table = ibus_panel_service_not_implemented; + class->page_up_lookup_table = ibus_panel_service_not_implemented; + class->reset = ibus_panel_service_not_implemented; + class->show_auxiliary_text = ibus_panel_service_not_implemented; + class->show_language_bar = ibus_panel_service_not_implemented; + class->show_lookup_table = ibus_panel_service_not_implemented; + class->show_preedit_text = ibus_panel_service_not_implemented; + class->start_setup = ibus_panel_service_not_implemented; + class->state_changed = ibus_panel_service_not_implemented; /* install properties */ + #if 0 /** * IBusPanelService:connection: * @@ -142,6 +144,7 @@ ibus_panel_service_class_init (IBusPanelServiceClass *klass) "The connection of service object", IBUS_TYPE_CONNECTION, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + #endif } static void @@ -150,41 +153,34 @@ ibus_panel_service_init (IBusPanelService *panel) } static void -ibus_panel_service_service_set_property (IBusPanelService *panel, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +ibus_panel_service_set_property (IBusPanelService *panel, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { switch (prop_id) { + #if 0 case PROP_CONNECTION: ibus_service_add_to_connection ((IBusService *) panel, g_value_get_object (value)); break; - + #endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (panel, prop_id, pspec); } } static void -ibus_panel_service_service_get_property (IBusPanelService *panel, - guint prop_id, - GValue *value, - GParamSpec *pspec) +ibus_panel_service_get_property (IBusPanelService *panel, + guint prop_id, + GValue *value, + GParamSpec *pspec) { switch (prop_id) { + #if 0 case PROP_CONNECTION: - { - GList *connections = ibus_service_get_connections ((IBusService *) panel); - if (connections) { - g_value_set_object (value, connections->data); - } - else { - g_value_set_object (value, NULL); - } - g_list_free (connections); - } break; + #endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (panel, prop_id, pspec); } @@ -196,14 +192,127 @@ ibus_panel_service_real_destroy (IBusPanelService *panel) IBUS_OBJECT_CLASS(ibus_panel_service_parent_class)->destroy (IBUS_OBJECT (panel)); } -static gboolean -ibus_panel_service_ibus_message (IBusPanelService *panel, - IBusConnection *connection, - IBusMessage *message) + +static void +_g_object_unref_if_floating (gpointer instance) { - g_assert (IBUS_IS_PANEL_SERVICE (panel)); - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (message != NULL); + if (g_object_is_floating (instance)) + g_object_unref (instance); +} + +static void +ibus_panel_service_service_method_call (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + IBusPanelService *panel = IBUS_PANEL_SERVICE (service); + + if (g_strcmp0 (interface_name, IBUS_INTERFACE_PANEL) != 0) { + IBUS_SERVICE_CLASS (ibus_panel_service_parent_class)-> + service_method_call (service, + connection, + sender, + object_path, + interface_name, + method_name, + parameters, + invocation); + return; + } + + if (g_strcmp0 (method_name, "UpdatePreeditText") == 0) { + GVariant *variant = NULL; + guint cursor = 0; + gboolean visible = FALSE; + + g_variant_get (parameters, "(vub)", &variant, &cursor, &visible); + IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + + IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_preedit_text (panel, text, cursor, visible); + _g_object_unref_if_floating (text); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "UpdateAuxiliaryText") == 0) { + GVariant *variant = NULL; + gboolean visible = FALSE; + + g_variant_get (parameters, "(vb)", &variant, &visible); + IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + + IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_auxiliary_text (panel, text, visible); + _g_object_unref_if_floating (text); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "UpdateLookupTable") == 0) { + GVariant *variant = NULL; + gboolean visible = FALSE; + + g_variant_get (parameters, "(vb)", &variant, &visible); + IBusLookupTable *table = IBUS_LOOKUP_TABLE (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + + IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_lookup_table (panel, table, visible); + _g_object_unref_if_floating (table); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "FocusIn") == 0) { + const gchar *path; + g_variant_get (parameters, "(&o)", &path); + IBUS_PANEL_SERVICE_GET_CLASS (panel)->focus_in (panel, path); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "FocusOut") == 0) { + const gchar *path; + g_variant_get (parameters, "(&o)", &path); + IBUS_PANEL_SERVICE_GET_CLASS (panel)->focus_out (panel, path); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "RegisterProperties") == 0) { + GVariant *variant = g_variant_get_child_value (parameters, 0); + IBusPropList *prop_list = IBUS_PROP_LIST (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + + IBUS_PANEL_SERVICE_GET_CLASS (panel)->register_properties (panel, prop_list); + _g_object_unref_if_floating (prop_list); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "UpdateProperty") == 0) { + GVariant *variant = g_variant_get_child_value (parameters, 0); + IBusProperty *property = IBUS_PROPERTY (ibus_serializable_deserialize (variant)); + g_variant_unref (variant); + + IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_property (panel, property); + _g_object_unref_if_floating (property); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "SetCursorLocation") == 0) { + guint x, y, w, h; + g_variant_get (parameters, "(uuuu)", &x, &y, &w, &h); + IBUS_PANEL_SERVICE_GET_CLASS (panel)->set_cursor_location (panel, x, y, w, h); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } const static struct { const gchar *name; @@ -227,421 +336,217 @@ ibus_panel_service_ibus_message (IBusPanelService *panel, { "StateChanged", G_STRUCT_OFFSET (IBusPanelServiceClass, state_changed) }, }; - IBusMessage *reply = NULL; - gint i; for (i = 0; i < G_N_ELEMENTS (no_arg_methods); i++) { - if (!ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, - no_arg_methods[i].name)) - continue; - - IBusMessageIter iter; - ibus_message_iter_init (message, &iter); - if (ibus_message_iter_has_next (&iter)) { - reply = ibus_message_new_error_printf (message, - DBUS_ERROR_INVALID_ARGS, - "%s.%s: Method does not have arguments", - IBUS_INTERFACE_PANEL, - no_arg_methods[i].name); - } - else { - IBusError *error = NULL; - typedef gboolean (* NoArgFunc) (IBusPanelService *, IBusError **); + if (g_strcmp0 (method_name, no_arg_methods[i].name) == 0) { + typedef gboolean (* NoArgFunc) (IBusPanelService *); NoArgFunc func; func = G_STRUCT_MEMBER (NoArgFunc, IBUS_PANEL_SERVICE_GET_CLASS (panel), no_arg_methods[i].offset); - if (!func (panel, &error)) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - } - else { - reply = ibus_message_new_method_return (message); - } - } - ibus_connection_send (connection, reply); - ibus_message_unref (reply); - return TRUE; - } - - if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "FocusIn")) { - const gchar* input_context_path = NULL; - IBusError *error = NULL; - gboolean retval; - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_OBJECT_PATH, - &input_context_path, - G_TYPE_INVALID); - - if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->focus_in (panel, - input_context_path, - &error)) { - reply = ibus_message_new_error (message, - error->name, - error->message); - ibus_error_free (error); - } - else { - reply = ibus_message_new_method_return (message); - } - } - else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "FocusOut")) { - const gchar* input_context_path = NULL; - gboolean retval; - IBusError *error = NULL; - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_OBJECT_PATH, - &input_context_path, - G_TYPE_INVALID); - - if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->focus_out (panel, - input_context_path, - &error)) { - reply = ibus_message_new_error(message, - error->name, - error->message); - ibus_error_free (error); - } - else { - reply = ibus_message_new_method_return (message); + func (panel); + g_dbus_method_invocation_return_value (invocation, NULL); + return; } } - else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "RegisterProperties")) { - IBusPropList *prop_list = NULL; - gboolean retval; - IBusError *error = NULL; - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_PROP_LIST, &prop_list, - G_TYPE_INVALID); - - if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->register_properties (panel, - prop_list, - &error)) { - reply = ibus_message_new_error(message, - error->name, - error->message); - ibus_error_free (error); - } - else { - reply = ibus_message_new_method_return (message); - } - if (prop_list != NULL && g_object_is_floating (prop_list)) - g_object_unref (prop_list); - } - else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateAuxiliaryText")) { - IBusText *text = NULL; - gboolean visible; - gboolean retval; - IBusError *error = NULL; - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_TEXT, &text, - G_TYPE_BOOLEAN, &visible, - G_TYPE_INVALID); - - if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_auxiliary_text (panel, - text, - visible, - &error)) { - reply = ibus_message_new_error(message, - error->name, - error->message); - ibus_error_free (error); - } - else { - reply = ibus_message_new_method_return (message); - } - - if (text != NULL && g_object_is_floating (text)) - g_object_unref (text); - } - else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateLookupTable")) { - IBusLookupTable *table = NULL; - gboolean visible = FALSE; - gboolean retval; - IBusError *error = NULL; - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_LOOKUP_TABLE, &table, - G_TYPE_BOOLEAN, &visible, - G_TYPE_INVALID); - - if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_lookup_table (panel, - table, - visible, - &error)) { - reply = ibus_message_new_error(message, - error->name, - error->message); - ibus_error_free (error); - } - else { - reply = ibus_message_new_method_return (message); - } - - if (table != NULL && g_object_is_floating (table)) - g_object_unref (table); - } - else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdatePreeditText")) { - IBusText *text = NULL; - guint cursor_pos; - gboolean visible; - gboolean retval; - IBusError *error = NULL; - - 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 || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_preedit_text (panel, - text, - cursor_pos, - visible, - &error)) { - reply = ibus_message_new_error(message, - error->name, - error->message); - ibus_error_free (error); - } - else { - reply = ibus_message_new_method_return (message); - } - - if (text != NULL && g_object_is_floating (text)) - g_object_unref (text); - } - else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateProperty")) { - IBusProperty *property = NULL; - gboolean retval; - IBusError *error = NULL; - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_PROPERTY, &property, - G_TYPE_INVALID); - - if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_property (panel, - property, - &error)) { - reply = ibus_message_new_error(message, - error->name, - error->message); - ibus_error_free (error); - } - else { - reply = ibus_message_new_method_return (message); - } - - if (property != NULL && g_object_is_floating (property)) - g_object_unref (property); - } - else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "SetCursorLocation")) { - guint x, y, w, h; - gboolean retval; - IBusError *error = NULL; - - retval = ibus_message_get_args (message, - &error, - G_TYPE_INT, &x, - G_TYPE_INT, &y, - G_TYPE_INT, &w, - G_TYPE_INT, &h, - G_TYPE_INVALID); - - if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->set_cursor_location (panel, - x, - y, - w, - h, - &error)) { - reply = ibus_message_new_error(message, - error->name, - error->message); - ibus_error_free (error); - } - else { - reply = ibus_message_new_method_return (message); - } - } - - if (reply) { - ibus_connection_send (connection, reply); - ibus_message_unref (reply); - return TRUE; - } + /* should not be reached */ + g_return_if_reached (); +} - return TRUE; +static GVariant * +ibus_panel_service_service_get_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error) +{ + return IBUS_SERVICE_CLASS (ibus_panel_service_parent_class)-> + service_get_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + error); } 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; +ibus_panel_service_service_set_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error) +{ + return IBUS_SERVICE_CLASS (ibus_panel_service_parent_class)-> + service_set_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + value, + error); } -static gboolean + +static void +ibus_panel_service_not_implemented (IBusPanelService *panel) +{ + /* g_debug ("not implemented"); */ +} + +static void ibus_panel_service_focus_in (IBusPanelService *panel, - const gchar *input_context_path, - IBusError **error) + const gchar *input_context_path) { - return ibus_panel_service_not_implemented(panel, error); + ibus_panel_service_not_implemented(panel); } -static gboolean +static void ibus_panel_service_focus_out (IBusPanelService *panel, - const gchar *input_context_path, - IBusError **error) + const gchar *input_context_path) { - return ibus_panel_service_not_implemented(panel, error); + ibus_panel_service_not_implemented(panel); } -static gboolean +static void ibus_panel_service_register_properties (IBusPanelService *panel, - IBusPropList *prop_list, - IBusError **error) + IBusPropList *prop_list) { - return ibus_panel_service_not_implemented(panel, error); + ibus_panel_service_not_implemented(panel); } -static gboolean +static void ibus_panel_service_set_cursor_location (IBusPanelService *panel, gint x, gint y, gint w, - gint h, - IBusError **error) + gint h) { - return ibus_panel_service_not_implemented(panel, error); + ibus_panel_service_not_implemented(panel); } -static gboolean +static void ibus_panel_service_update_auxiliary_text (IBusPanelService *panel, IBusText *text, - gboolean visible, - IBusError **error) + gboolean visible) { - return ibus_panel_service_not_implemented(panel, error); + ibus_panel_service_not_implemented(panel); } -static gboolean +static void ibus_panel_service_update_lookup_table (IBusPanelService *panel, IBusLookupTable *lookup_table, - gboolean visible, - IBusError **error) + gboolean visibl) { - return ibus_panel_service_not_implemented(panel, error); + ibus_panel_service_not_implemented(panel); } -static gboolean +static void ibus_panel_service_update_preedit_text (IBusPanelService *panel, IBusText *text, guint cursor_pos, - gboolean visible, - IBusError **error) + gboolean visible) { - return ibus_panel_service_not_implemented(panel, error); + ibus_panel_service_not_implemented(panel); } -static gboolean +static void ibus_panel_service_update_property (IBusPanelService *panel, - IBusProperty *prop, - IBusError **error) + IBusProperty *prop) { - return ibus_panel_service_not_implemented(panel, error); + ibus_panel_service_not_implemented(panel); } -void -ibus_panel_service_candidate_clicked (IBusPanelService *panel, - guint index, - guint button, - guint state) { - ibus_service_send_signal ((IBusService *) panel, - IBUS_INTERFACE_PANEL, - "CandidateClicked", - G_TYPE_UINT, &index, - G_TYPE_UINT, &button, - G_TYPE_UINT, &state, - G_TYPE_INVALID); -} - -void -ibus_panel_service_cursor_down (IBusPanelService *panel) { - ibus_service_send_signal ((IBusService *) panel, - IBUS_INTERFACE_PANEL, - "CursorDown", - G_TYPE_INVALID); -} +IBusPanelService * +ibus_panel_service_new (GDBusConnection *connection) +{ + g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); -void -ibus_panel_service_cursor_up (IBusPanelService *panel) { - ibus_service_send_signal ((IBusService *) panel, - IBUS_INTERFACE_PANEL, - "CursorUp", - G_TYPE_INVALID); -} + GObject *object = g_object_new (IBUS_TYPE_PANEL_SERVICE, + "object-path", IBUS_PATH_PANEL, + "connection", connection, + NULL); -void -ibus_panel_service_page_down (IBusPanelService *panel) { - ibus_service_send_signal ((IBusService *) panel, - IBUS_INTERFACE_PANEL, - "PageDown", - G_TYPE_INVALID); + return IBUS_PANEL_SERVICE (object); } void -ibus_panel_service_page_up (IBusPanelService *panel) { - ibus_service_send_signal ((IBusService *) panel, +ibus_panel_service_candidate_clicked (IBusPanelService *panel, + guint index, + guint button, + guint state) +{ + g_return_if_fail (IBUS_IS_PANEL_SERVICE (panel)); + ibus_service_emit_signal ((IBusService *) panel, + NULL, IBUS_INTERFACE_PANEL, - "PageUp", - G_TYPE_INVALID); + "CandidateClicked", + g_variant_new ("(uuu)", index, button, state), + NULL); } void ibus_panel_service_property_active (IBusPanelService *panel, const gchar *prop_name, - gint prop_state) { - ibus_service_send_signal ((IBusService *) panel, + gint prop_state) +{ + g_return_if_fail (IBUS_IS_PANEL_SERVICE (panel)); + ibus_service_emit_signal ((IBusService *) panel, + NULL, IBUS_INTERFACE_PANEL, - "PropertyActivate", - G_TYPE_STRING, &prop_name, - G_TYPE_INT, &prop_state, - G_TYPE_INVALID); + "PropertyActive", + g_variant_new ("(si)", prop_name, prop_state), + NULL); } void ibus_panel_service_property_show (IBusPanelService *panel, - const gchar *prop_name) { - ibus_service_send_signal ((IBusService *) panel, + const gchar *prop_name) +{ + g_return_if_fail (IBUS_IS_PANEL_SERVICE (panel)); + ibus_service_emit_signal ((IBusService *) panel, + NULL, IBUS_INTERFACE_PANEL, "PropertyShow", - G_TYPE_STRING, &prop_name, - G_TYPE_INVALID); + g_variant_new ("(s)", prop_name), + NULL); } void ibus_panel_service_property_hide (IBusPanelService *panel, - const gchar *prop_name) { - ibus_service_send_signal ((IBusService *) panel, + const gchar *prop_name) +{ + g_return_if_fail (IBUS_IS_PANEL_SERVICE (panel)); + ibus_service_emit_signal ((IBusService *) panel, + NULL, IBUS_INTERFACE_PANEL, "PropertyHide", - G_TYPE_STRING, &prop_name, - G_TYPE_INVALID); + g_variant_new ("(s)", prop_name), + NULL); } + +#define DEFINE_FUNC(name, Name) \ + void \ + ibus_panel_service_##name (IBusPanelService *panel) \ + { \ + g_return_if_fail (IBUS_IS_PANEL_SERVICE (panel)); \ + ibus_service_emit_signal ((IBusService *) panel, \ + NULL, \ + IBUS_INTERFACE_PANEL, \ + #Name, \ + NULL, \ + NULL); \ + } +DEFINE_FUNC (cursor_down, CursorDown) +DEFINE_FUNC (cursor_up, CursorUp) +DEFINE_FUNC (page_down, PageDown) +DEFINE_FUNC (page_up, PageUp) +#undef DEFINE_FUNC + diff --git a/src/ibuspanelservice.h b/src/ibuspanelservice.h index 7554a28..451b4c6 100644 --- a/src/ibuspanelservice.h +++ b/src/ibuspanelservice.h @@ -18,6 +18,11 @@ * 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: ibuspanelservice * @short_description: Panel service back-end. @@ -29,7 +34,6 @@ #ifndef __IBUS_PANEL_SERVICE_H_ #define __IBUS_PANEL_SERVICE_H_ -#include "ibusconnection.h" #include "ibuslookuptable.h" #include "ibusservice.h" #include "ibusproplist.h" @@ -71,69 +75,45 @@ struct _IBusPanelServiceClass { IBusServiceClass parent; /* class members */ - gboolean (* focus_in) (IBusPanelService *panel, - const gchar *input_context_path, - IBusError **error); - gboolean (* focus_out) (IBusPanelService *panel, - const gchar *input_context_path, - IBusError **error); - gboolean (* register_properties) (IBusPanelService *panel, - IBusPropList *prop_list, - IBusError **error); - gboolean (* set_cursor_location) (IBusPanelService *panel, + void (* focus_in) (IBusPanelService *panel, + const gchar *input_context_path); + void (* focus_out) (IBusPanelService *panel, + const gchar *input_context_path); + void (* register_properties) (IBusPanelService *panel, + IBusPropList *prop_list); + void (* set_cursor_location) (IBusPanelService *panel, gint x, gint y, gint w, - gint h, - IBusError **error); - gboolean (* update_auxiliary_text) (IBusPanelService *panel, + gint h); + void (* update_auxiliary_text) (IBusPanelService *panel, IBusText *text, - gboolean visible, - IBusError **error); - gboolean (* update_lookup_table) (IBusPanelService *panel, + gboolean visible); + void (* update_lookup_table) (IBusPanelService *panel, IBusLookupTable *lookup_table, - gboolean visible, - IBusError **error); - gboolean (* update_preedit_text) (IBusPanelService *panel, + gboolean visible); + void (* update_preedit_text) (IBusPanelService *panel, IBusText *text, guint cursor_pos, - gboolean visible, - IBusError **error); - gboolean (* update_property) (IBusPanelService *panel, - IBusProperty *prop, - IBusError **error); - gboolean (* cursor_down_lookup_table) (IBusPanelService *panel, - IBusError **error); - gboolean (* cursor_up_lookup_table) (IBusPanelService *panel, - IBusError **error); - gboolean (* destroy) (IBusPanelService *panel, - IBusError **error); - gboolean (* hide_auxiliary_text) (IBusPanelService *panel, - IBusError **error); - gboolean (* hide_language_bar) (IBusPanelService *panel, - IBusError **error); - gboolean (* hide_lookup_table) (IBusPanelService *panel, - IBusError **error); - gboolean (* hide_preedit_text) (IBusPanelService *panel, - IBusError **error); - gboolean (* page_down_lookup_table) (IBusPanelService *panel, - IBusError **error); - gboolean (* page_up_lookup_table) (IBusPanelService *panel, - IBusError **error); - gboolean (* reset) (IBusPanelService *panel, - IBusError **error); - gboolean (* show_auxiliary_text) (IBusPanelService *panel, - IBusError **error); - gboolean (* show_language_bar) (IBusPanelService *panel, - IBusError **error); - gboolean (* show_lookup_table) (IBusPanelService *panel, - IBusError **error); - gboolean (* show_preedit_text) (IBusPanelService *panel, - IBusError **error); - gboolean (* start_setup) (IBusPanelService *panel, - IBusError **error); - gboolean (* state_changed) (IBusPanelService *panel, - IBusError **error); + gboolean visible); + void (* update_property) (IBusPanelService *panel, + IBusProperty *prop); + void (* cursor_down_lookup_table) (IBusPanelService *panel); + void (* cursor_up_lookup_table) (IBusPanelService *panel); + void (* destroy) (IBusPanelService *panel); + void (* hide_auxiliary_text) (IBusPanelService *panel); + void (* hide_language_bar) (IBusPanelService *panel); + void (* hide_lookup_table) (IBusPanelService *panel); + void (* hide_preedit_text) (IBusPanelService *panel); + void (* page_down_lookup_table) (IBusPanelService *panel); + void (* page_up_lookup_table) (IBusPanelService *panel); + void (* reset) (IBusPanelService *panel); + void (* show_auxiliary_text) (IBusPanelService *panel); + void (* show_language_bar) (IBusPanelService *panel); + void (* show_lookup_table) (IBusPanelService *panel); + void (* show_preedit_text) (IBusPanelService *panel); + void (* start_setup) (IBusPanelService *panel); + void (* state_changed) (IBusPanelService *panel); /*< private >*/ /* padding */ @@ -144,12 +124,12 @@ GType ibus_panel_service_get_type (void); /** * ibus_panel_service_new: - * @connection: An IBusConnection. + * @connection: An GDBusConnection. * @returns: A newly allocated IBusPanelService. * - * New an IBusPanelService from an IBusConnection. + * New an IBusPanelService from an GDBusConnection. */ -IBusPanelService *ibus_panel_service_new (IBusConnection *connection); +IBusPanelService *ibus_panel_service_new (GDBusConnection *connection); /** * ibus_panel_service_candidate_clicked diff --git a/src/ibuspendingcall.c b/src/ibuspendingcall.c deleted file mode 100644 index b6f0759..0000000 --- a/src/ibuspendingcall.c +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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 -#include "ibuspendingcall.h" - -IBusPendingCall* -ibus_pending_call_ref (IBusPendingCall *pending) -{ - return dbus_pending_call_ref (pending); -} - -void -ibus_pending_call_unref (IBusPendingCall *pending) -{ - dbus_pending_call_unref (pending); -} - -gboolean -ibus_pending_call_set_notify (IBusPendingCall *pending, - IBusPendingCallNotifyFunction function, - gpointer user_data, - GDestroyNotify free_user_data) -{ - return dbus_pending_call_set_notify (pending, function, user_data, free_user_data); -} - -void -ibus_pending_call_cancel (IBusPendingCall *pending) -{ - dbus_pending_call_cancel (pending); -} - -gboolean -ibus_pending_call_get_completed (IBusPendingCall *pending) -{ - return dbus_pending_call_get_completed (pending); -} - -IBusMessage* -ibus_pending_call_steal_reply (IBusPendingCall *pending) -{ - return dbus_pending_call_steal_reply (pending); -} - -void -ibus_pending_call_block (IBusPendingCall *pending) -{ - dbus_pending_call_block (pending); -} - -void -ibus_pending_call_wait (IBusPendingCall *pending) -{ - g_assert (pending); - - while (!ibus_pending_call_get_completed (pending)) { - g_main_context_iteration (NULL, TRUE); - } -} - -gboolean -ibus_pending_call_allocate_data_slot (gint *slot_p) -{ - return dbus_pending_call_allocate_data_slot (slot_p); -} - -void -ibus_pending_call_free_data_slot (gint *slot_p) -{ - dbus_pending_call_free_data_slot (slot_p); -} - -gboolean -ibus_pending_call_set_data (IBusPendingCall *pending, - gint slot, - gpointer data, - GDestroyNotify free_data_func) -{ - return dbus_pending_call_set_data (pending, slot, data, free_data_func); -} - -gpointer -ibus_pending_call_get_data (IBusPendingCall *pending, - gint slot) -{ - return dbus_pending_call_get_data (pending, slot); -} diff --git a/src/ibuspendingcall.h b/src/ibuspendingcall.h deleted file mode 100644 index 650ba4f..0000000 --- a/src/ibuspendingcall.h +++ /dev/null @@ -1,210 +0,0 @@ -/* -*- 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 - * Copyright (C) 2008-2010 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 - * 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. - */ -/** - * SECTION: ibuspendingcall - * @title: IBusPendingCall - * @short_description: A DBusPendingCall in IBus. - * @stability: Stable - * - * An IBusPendingCall is essentially a DBusPendingCall, which representing an expected reply. - * A IBusPendingCall can be created when you send a message that should have a reply. - * - * Besides DBusPendingCall functions, An IBusPendingCall can be manipulated - * with its own specific functions, which are defined in this section. - */ -#ifndef __IBUS_PENDING_CALL_H_ -#define __IBUS_PENDING_CALL_H_ - -#include -#include "ibusdbus.h" -#include "ibusmessage.h" - -G_BEGIN_DECLS - -/** - * IBusPendingCallNotifyFunction: - * @pending: An IBusPendingCall. - * @user_data: User data for the callback function. - * - * Callback prototype of pending call notify function. - */ -typedef void (* IBusPendingCallNotifyFunction)(IBusPendingCall *pending, gpointer user_data); - -/** - * ibus_pending_call_ref: - * @pending: An IBusPendingCall. - * @returns: A reference of IBusPendingCall. - * - * Increases the reference count on a pending call. - */ -IBusPendingCall* ibus_pending_call_ref (IBusPendingCall *pending); - -/** - * ibus_pending_call_unref: - * @pending: An IBusPendingCall. - * - * Decreases the reference count on a pending call. - */ -void ibus_pending_call_unref (IBusPendingCall *pending); - -/** - * ibus_pending_call_set_notify: - * @pending: An IBusPendingCall. - * @function: An pending call notify callback function. - * @user_data: User data for the callback function. - * @free_user_data: Callback to free the user_data. - * @returns: TRUE if succeed; FALSE if not enough memory. - * - * Sets a notification function to be called when the reply is received or the pending call times out. - */ -gboolean ibus_pending_call_set_notify (IBusPendingCall *pending, - IBusPendingCallNotifyFunction function, - gpointer user_data, - GDestroyNotify free_user_data); - -/** - * ibus_pending_call_cancel: - * @pending: An IBusPendingCall. - * - * Cancels the pending call, such that any reply or error received will just be ignored. - * - * Drops the dbus library's internal reference to the DBusPendingCall so will free the call - * if nobody else is holding a reference. - * But usually application owns a reference from dbus_connection_send_with_reply(). - * - * Note that canceling a pending call will not simulate a timed-out call; - * if a call times out, then a timeout error reply is received. - * If you cancel the call, no reply is received unless the reply was already received before you canceled. - */ -void ibus_pending_call_cancel (IBusPendingCall *pending); - -/** - * ibus_pending_call_get_completed: - * @pending: An IBusPendingCall. - * @returns: TRUE if pending call has received a reply; FALSE otherwise. - * - * Whether the pending call has received a reply or not. - */ -gboolean ibus_pending_call_get_completed (IBusPendingCall *pending); - -/** - * ibus_pending_call_steal_reply: - * @pending: An IBusPendingCall. - * @returns: Replied message; NULL if none has been received yet. - * - * Gets the reply, or returns NULL if none has been received yet. - * - * Ownership of the reply message passes to the caller. - * This function can only be called once per pending call, - * since the reply message is transferred to the caller. - */ -IBusMessage* ibus_pending_call_steal_reply (IBusPendingCall *pending); - -/** - * ibus_pending_call_block: - * @pending: An IBusPendingCall. - * - * Block until the pending call is completed. - * The blocking is as with ibus_connection_send_with_reply_and_block(); - * it does not enter the main loop or process other messages, - * it simply waits for the reply in question. - * - * If the pending call is already completed, this function returns immediately. - */ -void ibus_pending_call_block (IBusPendingCall *pending); - -/** - * ibus_pending_call_wait: - * @pending: An IBusPendingCall. - * - * Wait until the pending call is completed. - * - * See also: ibus_pending_call_get_completed(). - */ -void ibus_pending_call_wait (IBusPendingCall *pending); - -/** - * ibus_pending_call_allocate_data_slot: - * @slot_p: Address of a global variable storing the slot. - * @returns: TRUE if succeed; FALSE if insufficient memory. - * - * Allocates an integer ID to be used for storing application-specific data on any IBusPendingCall. - * - * The allocated ID may then be used with ibus_pending_call_set_data() and ibus_pending_call_get_data(). - * The passed-in slot must be initialized to -1, and is filled in with the slot ID. - * If the passed-in slot is not -1, it's assumed to be already allocated, and - * its reference count is increased. - * - * The allocated slot is global, i.e. all DBusPendingCall objects - * will have a slot with the given integer ID reserved. - */ -gboolean ibus_pending_call_allocate_data_slot - (gint *slot_p); - -/** - * ibus_pending_call_free_data_slot: - * @slot_p: Address of a global variable storing the slot. - * - * Deallocates a global ID for IBusPendingCall data slots. - * - * ibus_pending_call_get_data() and ibus_pending_call_set_data() may no longer be used with this slot. - * Existing data stored on existing IBusPendingCall objects will be freed when - * the IBusPendingCall is finalized, but may not be retrieved - * (and may only be replaced if someone else reallocates the slot). - * When the reference count on the passed-in slot reaches 0, it is set to -1. - */ -void ibus_pending_call_free_data_slot - (gint *slot_p); - -/** - * ibus_pending_call_set_data: - * @pending: An IBusPendingCall. - * @slot: The slot number. - * @data: The data to store - * @free_data_func: Callback to free the data. - * @returns: TRUE if there was enough memory to store the data; FALSE otherwise. - * - * Stores a pointer on a IBusPendingCall, along with an optional function - * to be used for freeing the data when the data is set again, or when the pending call is finalized. - * - * The slot number must have been allocated with ibus_pending_call_allocate_data_slot(). - */ -gboolean ibus_pending_call_set_data (IBusPendingCall *pending, - gint slot, - gpointer data, - GDestroyNotify free_data_func); - -/** - * ibus_pending_call_get_data: - * @pending: An IBusPendingCall. - * @slot: The slot number. - * @returns: The stored data; NULL if no such data. - * - * Retrieves data previously set with ibus_pending_call_set_data(). - * - * The slot must still be allocated (must not have been freed). - */ -gpointer ibus_pending_call_get_data (IBusPendingCall *pending, - gint slot); - -G_END_DECLS -#endif diff --git a/src/ibusproperty.c b/src/ibusproperty.c index 07f4f83..52a8210 100644 --- a/src/ibusproperty.c +++ b/src/ibusproperty.c @@ -25,27 +25,25 @@ /* functions prototype */ static void ibus_property_destroy (IBusProperty *prop); static gboolean ibus_property_serialize (IBusProperty *prop, - IBusMessageIter *iter); -static gboolean ibus_property_deserialize (IBusProperty *prop, - IBusMessageIter *iter); + GVariantBuilder *builder); +static gint ibus_property_deserialize (IBusProperty *prop, + GVariant *variant); static gboolean ibus_property_copy (IBusProperty *dest, const IBusProperty *src); G_DEFINE_TYPE (IBusProperty, ibus_property, IBUS_TYPE_SERIALIZABLE) static void -ibus_property_class_init (IBusPropertyClass *klass) +ibus_property_class_init (IBusPropertyClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); - IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); + IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class); object_class->destroy = (IBusObjectDestroyFunc) ibus_property_destroy; serializable_class->serialize = (IBusSerializableSerializeFunc) ibus_property_serialize; serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_property_deserialize; serializable_class->copy = (IBusSerializableCopyFunc) ibus_property_copy; - - g_string_append (serializable_class->signature, "suvsvbbuv"); } static void @@ -92,97 +90,62 @@ ibus_property_destroy (IBusProperty *prop) gboolean ibus_property_serialize (IBusProperty *prop, - IBusMessageIter *iter) + GVariantBuilder *builder) { gboolean retval; - retval = IBUS_SERIALIZABLE_CLASS (ibus_property_parent_class)->serialize ((IBusSerializable *) prop, iter); + retval = IBUS_SERIALIZABLE_CLASS (ibus_property_parent_class)->serialize ((IBusSerializable *) prop, builder); g_return_val_if_fail (retval, FALSE); g_return_val_if_fail (IBUS_IS_PROPERTY (prop), FALSE); - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &prop->key); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_UINT, &prop->type); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, IBUS_TYPE_TEXT, &prop->label); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &prop->icon); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, IBUS_TYPE_TEXT, &prop->tooltip); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_BOOLEAN, &prop->sensitive); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_BOOLEAN, &prop->visible); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, G_TYPE_UINT, &prop->state); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_append (iter, IBUS_TYPE_PROP_LIST, &prop->sub_props); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "s", prop->key); + g_variant_builder_add (builder, "u", prop->type); + g_variant_builder_add (builder, "v", ibus_serializable_serialize ((IBusSerializable *)prop->label)); + g_variant_builder_add (builder, "s", prop->icon); + g_variant_builder_add (builder, "v", ibus_serializable_serialize ((IBusSerializable *)prop->tooltip)); + g_variant_builder_add (builder, "b", prop->sensitive); + g_variant_builder_add (builder, "b", prop->visible); + g_variant_builder_add (builder, "u", prop->state); + g_variant_builder_add (builder, "v", ibus_serializable_serialize ((IBusSerializable *)prop->sub_props)); return TRUE; } -static gboolean -ibus_property_deserialize (IBusProperty *prop, - IBusMessageIter *iter) +static gint +ibus_property_deserialize (IBusProperty *prop, + GVariant *variant) { - gboolean retval; - gchar *p; + gint retval; - retval = IBUS_SERIALIZABLE_CLASS (ibus_property_parent_class)->deserialize ((IBusSerializable *) prop, iter); - g_return_val_if_fail (retval, FALSE); + retval = IBUS_SERIALIZABLE_CLASS (ibus_property_parent_class)->deserialize ((IBusSerializable *) prop, variant); + g_return_val_if_fail (retval, 0); - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &p); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - prop->key = g_strdup (p); + g_variant_get_child (variant, retval++, "s", &prop->key); + g_variant_get_child (variant, retval++, "u", &prop->type); - retval = ibus_message_iter_get (iter, G_TYPE_UINT, &prop->type); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - - retval = ibus_message_iter_get (iter, IBUS_TYPE_TEXT, &prop->label); + GVariant *subvar = g_variant_get_child_value (variant, retval++); + prop->label = IBUS_TEXT (ibus_serializable_deserialize (subvar)); g_object_ref_sink (prop->label); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); + g_variant_unref (subvar); - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &p); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - prop->icon = g_strdup (p); + g_variant_get_child (variant, retval++, "s", &prop->icon); - retval = ibus_message_iter_get (iter, IBUS_TYPE_TEXT, &prop->tooltip); + subvar = g_variant_get_child_value (variant, retval++); + prop->tooltip = IBUS_TEXT (ibus_serializable_deserialize (subvar)); g_object_ref_sink (prop->tooltip); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); + g_variant_unref (subvar); - retval = ibus_message_iter_get (iter, G_TYPE_BOOLEAN, &prop->sensitive); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - - retval = ibus_message_iter_get (iter, G_TYPE_BOOLEAN, &prop->visible); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - - retval = ibus_message_iter_get (iter, G_TYPE_UINT, &prop->state); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); + g_variant_get_child (variant, retval++, "b", &prop->sensitive); + g_variant_get_child (variant, retval++, "b", &prop->visible); + g_variant_get_child (variant, retval++, "u", &prop->state); - retval = ibus_message_iter_get (iter, IBUS_TYPE_PROP_LIST, &prop->sub_props); + subvar = g_variant_get_child_value (variant, retval++); + prop->sub_props = IBUS_PROP_LIST (ibus_serializable_deserialize (subvar)); g_object_ref_sink (prop->sub_props); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); + g_variant_unref (subvar); - return TRUE; + return retval; } static gboolean @@ -242,7 +205,7 @@ ibus_property_new (const gchar *key, prop->key = g_strdup (key); prop->type = type; - + ibus_property_set_label (prop, label); ibus_property_set_icon (prop, icon); ibus_property_set_tooltip (prop, tooltip); diff --git a/src/ibusproperty.h b/src/ibusproperty.h index ca8485b..0f8d427 100644 --- a/src/ibusproperty.h +++ b/src/ibusproperty.h @@ -19,6 +19,11 @@ * 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: ibusproperty * @short_description: UI component for input method engine property. diff --git a/src/ibusproplist.c b/src/ibusproplist.c index abb2321..f1c6b27 100644 --- a/src/ibusproplist.c +++ b/src/ibusproplist.c @@ -19,33 +19,30 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include "ibusproplist.h" /* functions prototype */ static void ibus_prop_list_destroy (IBusPropList *prop_list); static gboolean ibus_prop_list_serialize (IBusPropList *prop_list, - IBusMessageIter *iter); -static gboolean ibus_prop_list_deserialize (IBusPropList *prop_list, - IBusMessageIter *iter); + GVariantBuilder *builder); +static gint ibus_prop_list_deserialize (IBusPropList *prop_list, + GVariant *variant); static gboolean ibus_prop_list_copy (IBusPropList *dest, const IBusPropList *src); G_DEFINE_TYPE (IBusPropList, ibus_prop_list, IBUS_TYPE_SERIALIZABLE) static void -ibus_prop_list_class_init (IBusPropListClass *klass) +ibus_prop_list_class_init (IBusPropListClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); - IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); + IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class); object_class->destroy = (IBusObjectDestroyFunc) ibus_prop_list_destroy; serializable_class->serialize = (IBusSerializableSerializeFunc) ibus_prop_list_serialize; serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_prop_list_deserialize; serializable_class->copy = (IBusSerializableCopyFunc) ibus_prop_list_copy; - - g_string_append (serializable_class->signature, "av"); } static void @@ -72,60 +69,49 @@ ibus_prop_list_destroy (IBusPropList *prop_list) static gboolean ibus_prop_list_serialize (IBusPropList *prop_list, - IBusMessageIter *iter) + GVariantBuilder *builder) { gboolean retval; - IBusMessageIter array_iter; - IBusProperty *prop; guint i; - retval = IBUS_SERIALIZABLE_CLASS (ibus_prop_list_parent_class)->serialize ((IBusSerializable *) prop_list, iter); + retval = IBUS_SERIALIZABLE_CLASS (ibus_prop_list_parent_class)->serialize ((IBusSerializable *) prop_list, builder); g_return_val_if_fail (retval, FALSE); - retval = ibus_message_iter_open_container (iter, IBUS_TYPE_ARRAY, "v", &array_iter); - g_return_val_if_fail (retval, FALSE); - - i = 0; - - while ((prop = ibus_prop_list_get (prop_list, i)) != NULL) { - retval = ibus_message_iter_append (&array_iter, IBUS_TYPE_PROPERTY, &prop); - g_return_val_if_fail (retval, FALSE); - i ++; + GVariantBuilder array; + g_variant_builder_init (&array, G_VARIANT_TYPE ("av")); + for (i = 0;; i++) { + IBusProperty *prop = ibus_prop_list_get (prop_list, i); + if (prop == NULL) + break; + g_variant_builder_add (&array, "v", ibus_serializable_serialize ((IBusSerializable *)prop)); } - retval = ibus_message_iter_close_container (iter, &array_iter); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "av", &array); return TRUE; } -gboolean +gint ibus_prop_list_deserialize (IBusPropList *prop_list, - IBusMessageIter *iter) + GVariant *variant) { - gboolean retval; - IBusMessageIter array_iter; - IBusProperty *prop; - - retval = IBUS_SERIALIZABLE_CLASS (ibus_prop_list_parent_class)->deserialize ((IBusSerializable *) prop_list, iter); - g_return_val_if_fail (retval, FALSE); + gint retval; - g_return_val_if_fail (IBUS_IS_PROP_LIST (prop_list), FALSE); + retval = IBUS_SERIALIZABLE_CLASS (ibus_prop_list_parent_class)->deserialize ((IBusSerializable *) prop_list, variant); + g_return_val_if_fail (retval, 0); - retval = ibus_message_iter_recurse (iter, IBUS_TYPE_ARRAY, &array_iter); - g_return_val_if_fail (retval, FALSE); - - while (ibus_message_iter_get_arg_type (&array_iter) != G_TYPE_INVALID) { - retval = ibus_message_iter_get (&array_iter, IBUS_TYPE_PROPERTY, &prop); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (&array_iter); + g_return_val_if_fail (IBUS_IS_PROP_LIST (prop_list), 0); - ibus_prop_list_append (prop_list, prop); + GVariantIter *iter = NULL; + g_variant_get_child (variant, retval++, "av", &iter); + g_return_val_if_fail (iter != NULL, retval); + GVariant *var; + while (g_variant_iter_loop (iter, "v", &var)) { + ibus_prop_list_append (prop_list, IBUS_PROPERTY (ibus_serializable_deserialize (var))); } + g_variant_iter_free (iter); - ibus_message_iter_next (iter); - - return TRUE; + return retval; } diff --git a/src/ibusproplist.h b/src/ibusproplist.h index 3940215..91c1284 100644 --- a/src/ibusproplist.h +++ b/src/ibusproplist.h @@ -19,6 +19,11 @@ * 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: ibusproplist * @Title: IBusPropList diff --git a/src/ibusproxy.c b/src/ibusproxy.c index 16ac7e6..7999f97 100644 --- a/src/ibusproxy.c +++ b/src/ibusproxy.c @@ -20,714 +20,129 @@ * Boston, MA 02111-1307, USA. */ -#include -#include -#include "ibusmessage.h" #include "ibusproxy.h" +#include "ibusmarshalers.h" #include "ibusinternal.h" +#include "ibusobject.h" #define IBUS_PROXY_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_PROXY, IBusProxyPrivate)) enum { - IBUS_SIGNAL, + DESTROY, LAST_SIGNAL, }; -enum { - PROP_0, - PROP_NAME, - PROP_PATH, - PROP_INTERFACE, - PROP_CONNECTION, -}; - - -/* IBusProxyPriv */ -struct _IBusProxyPrivate { - gchar *name; - gchar *unique_name; - gchar *path; - gchar *interface; - IBusConnection *connection; -}; -typedef struct _IBusProxyPrivate IBusProxyPrivate; - static guint proxy_signals[LAST_SIGNAL] = { 0 }; /* functions prototype */ -static GObject *ibus_proxy_constructor (GType type, - guint n_construct_params, - GObjectConstructParam *construct_params); -static void ibus_proxy_destroy (IBusProxy *proxy); -static void ibus_proxy_set_property(IBusProxy *proxy, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void ibus_proxy_get_property(IBusProxy *proxy, - guint prop_id, - GValue *value, - GParamSpec *pspec); +static void ibus_proxy_constructed (GObject *object); +static void ibus_proxy_dispose (GObject *object); +static void ibus_proxy_real_destroy (IBusProxy *proxy); -static gboolean ibus_proxy_ibus_signal (IBusProxy *proxy, - IBusMessage *message); +static void ibus_proxy_connection_closed_cb + (GDBusConnection *connection, + gboolean remote_peer_vanished, + GError *error, + IBusProxy *proxy); -G_DEFINE_TYPE (IBusProxy, ibus_proxy, IBUS_TYPE_OBJECT) - -IBusProxy * -ibus_proxy_new (const gchar *name, - const gchar *path, - IBusConnection *connection) -{ - g_assert (name != NULL); - g_assert (path != NULL); - g_assert (IBUS_IS_CONNECTION (connection)); - - IBusProxy *proxy; - - proxy = IBUS_PROXY (g_object_new (IBUS_TYPE_PROXY, - "name", name, - "path", path, - "connection", connection, - NULL)); - - return proxy; -} +G_DEFINE_TYPE (IBusProxy, ibus_proxy, G_TYPE_DBUS_PROXY) static void -ibus_proxy_class_init (IBusProxyClass *klass) +ibus_proxy_class_init (IBusProxyClass *class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IBusProxyPrivate)); - - gobject_class->constructor = ibus_proxy_constructor; - gobject_class->set_property = (GObjectSetPropertyFunc) ibus_proxy_set_property; - gobject_class->get_property = (GObjectGetPropertyFunc) ibus_proxy_get_property; + GObjectClass *gobject_class = G_OBJECT_CLASS (class); - ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_proxy_destroy; + gobject_class->constructed = ibus_proxy_constructed; + gobject_class->dispose = ibus_proxy_dispose; - klass->ibus_signal = ibus_proxy_ibus_signal; - - /* install properties */ - /** - * IBusProxy:name: - * - * The service name of the proxy object. - */ - g_object_class_install_property (gobject_class, - PROP_NAME, - g_param_spec_string ("name", - "service name", - "The service name of proxy object", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - /** - * IBusProxy:path: - * - * The path of the proxy object. - */ - g_object_class_install_property (gobject_class, - PROP_PATH, - g_param_spec_string ("path", - "object path", - "The path of proxy object", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - /** - * IBusProxy:interface: - * - * The interface of the proxy object. - */ - g_object_class_install_property (gobject_class, - PROP_INTERFACE, - g_param_spec_string ("interface", - "interface", - "The interface of proxy object", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - /** - * IBusProxy:connection: - * - * The connection of the proxy object. - */ - g_object_class_install_property (gobject_class, - PROP_CONNECTION, - g_param_spec_object ("connection", - "object path", - "The path of proxy object", - IBUS_TYPE_CONNECTION, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + class->destroy = ibus_proxy_real_destroy; /* install signals */ /** - * IBusProxy::ibus-signal: - * @proxy: An IBusProxy. - * @message: An message that contains the signal. + * IBusProxy::destroy: + * @object: An IBusProxy. * - * Emitted when sending a signal. - * Implement the member function ibus_signal() in extended class to receive this signal. + * Destroy and free an IBusProxy * - * Argument @user_data is ignored in this function. - * Returns: TRUE if the path of @message is identical to IBusProxy:path and successfully handled. + * See also: ibus_proxy_destroy(). * - * @see_also: ibus_proxy_handle_signal(). + * Argument @user_data is ignored in this function. */ - proxy_signals[IBUS_SIGNAL] = - g_signal_new (I_("ibus-signal"), - G_TYPE_FROM_CLASS (klass), + proxy_signals[DESTROY] = + g_signal_new (I_("destroy"), + G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (IBusProxyClass, ibus_signal), + G_STRUCT_OFFSET (IBusProxyClass, destroy), NULL, NULL, - ibus_marshal_BOOLEAN__POINTER, - G_TYPE_BOOLEAN, - 1, G_TYPE_POINTER); - -} - -static gboolean -_connection_ibus_signal_cb (IBusConnection *connection, - IBusMessage *message, - IBusProxy *proxy) -{ - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - if (g_strcmp0 (ibus_message_get_path (message), priv->path) != 0) - return FALSE; - - if (ibus_proxy_handle_signal (proxy, message)) { - g_signal_stop_emission_by_name (connection, "ibus-signal"); - return TRUE; - } - - return FALSE; -} - -static void -_connection_destroy_cb (IBusConnection *connection, - IBusProxy *proxy) -{ - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - g_assert (priv->connection == connection); - - g_object_unref (connection); - priv->connection = NULL; - - ibus_object_destroy ((IBusObject *) proxy); -} - -static GObject * -ibus_proxy_constructor (GType type, - guint n_construct_params, - GObjectConstructParam *construct_params) -{ - GObject *obj; - IBusProxy *proxy; - IBusProxyPrivate *priv; - - obj = G_OBJECT_CLASS (ibus_proxy_parent_class)->constructor (type, n_construct_params, construct_params); - - proxy = IBUS_PROXY (obj); - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - if (priv->connection == NULL) { - g_object_unref (proxy); - return NULL; - } - - if (priv->name != NULL) { - IBusError *error; - gchar *rule; - - if (ibus_proxy_get_unique_name (proxy) == NULL) { - g_object_unref (proxy); - return NULL; - } - - rule = g_strdup_printf ("type='signal'," - "sender='" DBUS_SERVICE_DBUS "'," - "path='" DBUS_PATH_DBUS "'," - "interface='" DBUS_INTERFACE_DBUS "'," - "member='NameOwnerChanged'," - "arg0='%s'", - priv->unique_name); - - if (!ibus_connection_call (priv->connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "AddMatch", - &error, - G_TYPE_STRING, &rule, - G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } - g_free (rule); - - rule = g_strdup_printf ("type='signal'," - "sender='%s'," - "path='%s'", - priv->unique_name, - priv->path); - - if (!ibus_connection_call (priv->connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "AddMatch", - &error, - G_TYPE_STRING, &rule, - G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } - g_free (rule); - } - g_signal_connect (priv->connection, - "ibus-signal", - (GCallback) _connection_ibus_signal_cb, - proxy); - - g_signal_connect (priv->connection, - "destroy", - (GCallback) _connection_destroy_cb, - proxy); - return obj; + _ibus_marshal_VOID__VOID, + G_TYPE_NONE, 0); } static void ibus_proxy_init (IBusProxy *proxy) { - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - priv->name = NULL; - priv->unique_name = NULL; - priv->path = NULL; - priv->interface = NULL; - priv->connection = NULL; } static void -ibus_proxy_destroy (IBusProxy *proxy) +ibus_proxy_constructed (GObject *object) { - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - if (priv->connection) { - /* disconnect signal handlers */ - g_signal_handlers_disconnect_by_func (priv->connection, - (GCallback) _connection_ibus_signal_cb, - proxy); - g_signal_handlers_disconnect_by_func (priv->connection, - (GCallback) _connection_destroy_cb, - proxy); - - /* remove match rules */ - if (priv->name != NULL && ibus_connection_is_connected (priv->connection)) { - - IBusError *error; - gchar *rule; - - rule = g_strdup_printf ("type='signal'," - "sender='" DBUS_SERVICE_DBUS "'," - "path='" DBUS_PATH_DBUS "'," - "interface='" DBUS_INTERFACE_DBUS "'," - "member='NameOwnerChanged'," - "arg0='%s'", - priv->unique_name); - - if (!ibus_connection_call (priv->connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "RemoveMatch", - &error, - G_TYPE_STRING, &rule, - G_TYPE_INVALID)) { - - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } - g_free (rule); - - rule = g_strdup_printf ("type='signal'," - "sender='%s'," - "path='%s'", - priv->unique_name, - priv->path); - - if (!ibus_connection_call (priv->connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "RemoveMatch", - &error, - G_TYPE_STRING, &rule, - G_TYPE_INVALID)) { - - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } - g_free (rule); - - } - } - - g_free (priv->name); - g_free (priv->unique_name); - g_free (priv->path); - g_free (priv->interface); - - priv->name = NULL; - priv->path = NULL; - priv->interface = NULL; + GDBusConnection *connection; + connection = g_dbus_proxy_get_connection ((GDBusProxy *)object); - if (priv->connection) { - g_object_unref (priv->connection); - priv->connection = NULL; - } - - IBUS_OBJECT_CLASS(ibus_proxy_parent_class)->destroy (IBUS_OBJECT (proxy)); -} + g_assert (connection); + g_assert (!g_dbus_connection_is_closed (connection)); -static void -ibus_proxy_set_property (IBusProxy *proxy, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); + g_signal_connect (connection, "closed", + G_CALLBACK (ibus_proxy_connection_closed_cb), object); - switch (prop_id) { - case PROP_NAME: - g_assert (priv->name == NULL); - priv->name = g_strdup (g_value_get_string (value)); - break; - case PROP_PATH: - g_assert (priv->path == NULL); - priv->path = g_strdup (g_value_get_string (value)); - break; - case PROP_INTERFACE: - g_assert (priv->interface == NULL); - priv->interface = g_strdup (g_value_get_string (value)); - break; - case PROP_CONNECTION: - g_assert (priv->connection == NULL); - priv->connection = IBUS_CONNECTION (g_value_get_object (value)); - g_object_ref_sink (priv->connection); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (proxy, prop_id, pspec); - } + /* FIXME add match rules? */ } static void -ibus_proxy_get_property (IBusProxy *proxy, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) { - case PROP_NAME: - g_value_set_string (value, ibus_proxy_get_name (proxy)); - break; - case PROP_PATH: - g_value_set_string (value, ibus_proxy_get_path (proxy)); - break; - case PROP_INTERFACE: - g_value_set_string (value, ibus_proxy_get_interface (proxy)); - break; - case PROP_CONNECTION: - g_value_set_object (value, ibus_proxy_get_connection (proxy)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (proxy, prop_id, pspec); - } -} - - -gboolean -ibus_proxy_handle_signal (IBusProxy *proxy, - DBusMessage *message) +ibus_proxy_dispose (GObject *object) { - g_assert (IBUS_IS_PROXY (proxy)); - g_assert (message != NULL); - - gboolean retval = FALSE; - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - if (ibus_message_is_signal (message, DBUS_SERVICE_DBUS, "NameOwnerChanged")) { - gchar *name, *old_name, *new_name; - IBusError *error; - - if (!ibus_message_get_args (message, - &error, - G_TYPE_STRING, &name, - G_TYPE_STRING, &old_name, - G_TYPE_STRING, &new_name, - G_TYPE_INVALID)) { - g_warning ("%s :%s", error->name, error->message); - ibus_error_free (error); - } - - if (g_strcmp0 (priv->unique_name, old_name) == 0) { - ibus_object_destroy (IBUS_OBJECT (proxy)); - return FALSE; + if (! (IBUS_PROXY_FLAGS (object) & IBUS_IN_DESTRUCTION)) { + IBUS_PROXY_SET_FLAGS (object, IBUS_IN_DESTRUCTION); + if (! (IBUS_PROXY_FLAGS (object) & IBUS_DESTROYED)) { + g_signal_emit (object, proxy_signals[DESTROY], 0); + IBUS_PROXY_SET_FLAGS (object, IBUS_DESTROYED); } + IBUS_PROXY_UNSET_FLAGS (object, IBUS_IN_DESTRUCTION); } - if (g_strcmp0 (ibus_message_get_path (message), priv->path) == 0) { - g_signal_emit (proxy, proxy_signals[IBUS_SIGNAL], 0, message, &retval); - } - - return retval; -} - -static gboolean -ibus_proxy_ibus_signal (IBusProxy *proxy, - DBusMessage *message) -{ - return FALSE; + G_OBJECT_CLASS(ibus_proxy_parent_class)->dispose (object); } - -const gchar * -ibus_proxy_get_name (IBusProxy *proxy) -{ - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - return priv->name; -} - -const gchar * -ibus_proxy_get_unique_name (IBusProxy *proxy) -{ - - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - if (priv->unique_name == NULL && priv->connection != NULL) { - IBusMessage *reply = NULL; - IBusError *error = NULL; - gchar *owner = NULL; - reply = ibus_connection_call_with_reply (priv->connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "GetNameOwner", - NULL, - G_TYPE_STRING, &(priv->name), - G_TYPE_INVALID); - if (reply) { - if (ibus_message_get_args (reply, &error, G_TYPE_STRING, &owner, - G_TYPE_INVALID)) { - priv->unique_name = g_strdup (owner); - } else { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } - - ibus_message_unref (reply); - } +static void +ibus_proxy_real_destroy (IBusProxy *proxy) +{ + GDBusConnection *connection = g_dbus_proxy_get_connection ((GDBusProxy *) proxy); + if (connection != NULL && !g_dbus_connection_is_closed (connection)) { + g_dbus_proxy_call ((GDBusProxy *)proxy, + "org.freedesktop.IBus.Service.Destroy", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); } - - return priv->unique_name; -} - -const gchar * -ibus_proxy_get_path (IBusProxy *proxy) -{ - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - return priv->path; -} - -const gchar * -ibus_proxy_get_interface (IBusProxy *proxy) -{ - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - return priv->interface; } -IBusConnection * -ibus_proxy_get_connection (IBusProxy *proxy) -{ - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - return priv->connection; -} - -gboolean -ibus_proxy_send (IBusProxy *proxy, - DBusMessage *message) -{ - g_assert (IBUS_IS_PROXY (proxy)); - g_assert (message != NULL); - - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - g_return_val_if_fail (priv->connection, FALSE); - g_return_val_if_fail (ibus_connection_is_connected (priv->connection), FALSE); - - return ibus_connection_send (priv->connection, message); -} - -gboolean -ibus_proxy_call (IBusProxy *proxy, - const gchar *method, - GType first_arg_type, - ...) +static void +ibus_proxy_connection_closed_cb (GDBusConnection *connection, + gboolean remote_peer_vanished, + GError *error, + IBusProxy *proxy) { - g_assert (IBUS_IS_PROXY (proxy)); - g_assert (method != NULL); - - va_list args; - gboolean retval; - DBusMessage *message; - - IBusProxyPrivate *priv; - priv = IBUS_PROXY_GET_PRIVATE (proxy); - - g_return_val_if_fail (priv->connection, FALSE); - g_return_val_if_fail (ibus_connection_is_connected (priv->connection), 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); - if (!retval) { - ibus_message_unref (message); - g_return_val_if_reached (FALSE); - } - - va_end (args); - - retval = ibus_connection_send (priv->connection, message); - - ibus_message_unref (message); - - return retval; + ibus_proxy_destroy (proxy); } -gboolean -ibus_proxy_call_with_reply (IBusProxy *proxy, - const gchar *method, - IBusPendingCall **pending, - gint timeout_milliseconds, - IBusError **error, - GType first_arg_type, - ...) +void +ibus_proxy_destroy (IBusProxy *proxy) { - 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); + g_return_if_fail (IBUS_IS_PROXY (proxy)); - if (!retval && error != NULL) { - *error = ibus_error_new_from_printf (DBUS_ERROR_NO_MEMORY, ""); + if (! (IBUS_PROXY_FLAGS (proxy) & IBUS_IN_DESTRUCTION)) { + g_object_run_dispose (G_OBJECT (proxy)); } - - return retval; } - -IBusMessage * -ibus_proxy_call_with_reply_and_block (IBusProxy *proxy, - const gchar *method, - gint timeout_milliseconds, - IBusError **error, - GType first_arg_type, - ...) -{ - g_assert (IBUS_IS_PROXY (proxy)); - g_assert (method != NULL); - - va_list args; - gboolean retval; - DBusMessage *message; - DBusMessage *reply_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 NULL; - } - - 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); - - reply_message = ibus_connection_send_with_reply_and_block ( - priv->connection, - message, - timeout_milliseconds, - error); - ibus_message_unref (message); - - return reply_message; -} diff --git a/src/ibusproxy.h b/src/ibusproxy.h index b7d8f79..97eb6af 100644 --- a/src/ibusproxy.h +++ b/src/ibusproxy.h @@ -19,6 +19,11 @@ * 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: ibusproxy * @short_description: Base proxy object. @@ -34,9 +39,7 @@ #ifndef __IBUS_PROXY_H_ #define __IBUS_PROXY_H_ -#include "ibusobject.h" -#include "ibusconnection.h" -#include "ibusmessage.h" +#include /* * Type macros. @@ -61,22 +64,27 @@ G_BEGIN_DECLS typedef struct _IBusProxy IBusProxy; typedef struct _IBusProxyClass IBusProxyClass; +#define IBUS_PROXY_FLAGS(obj) (IBUS_PROXY (obj)->flags) +#define IBUS_PROXY_SET_FLAGS(obj,flag) G_STMT_START{ (IBUS_PROXY_FLAGS (obj) |= (flag)); }G_STMT_END +#define IBUS_PROXY_UNSET_FLAGS(obj,flag) G_STMT_START{ (IBUS_PROXY_FLAGS (obj) &= ~(flag)); }G_STMT_END +#define IBUS_PROXY_DESTROYED(obj) (IBUS_PROXY_FLAGS (obj) & IBUS_DESTROYED) + /** * IBusProxy: * * An opaque data type representing an IBusProxy. */ struct _IBusProxy { - IBusObject parent; + GDBusProxy parent; /* instance members */ + guint32 flags; }; struct _IBusProxyClass { - IBusObjectClass parent; + GDBusProxyClass parent; /* class members */ - gboolean (* ibus_signal) (IBusProxy *proxy, - IBusMessage *message); + void (* destroy) (IBusProxy *proxy); /*< private >*/ /* padding */ gpointer pdummy[7]; @@ -84,204 +92,7 @@ struct _IBusProxyClass { GType ibus_proxy_get_type (void); -/** - * ibus_proxy_new: - * @name: The service name of proxy object. - * @path: The path of proxy object. - * @connection: An IBusConnection. - * @returns: A newly allocated IBusProxy instance. - * - * New an IBusProxy instance. - * Property IBusProxy:name is set as @name, and - * IBusProxy:path is set as @path. - */ -IBusProxy *ibus_proxy_new (const gchar *name, - const gchar *path, - IBusConnection *connection); - -/** - * ibus_proxy_send: - * @proxy: An IBusProxy. - * @message: The IBusMessage to be sent. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Send an #IBusMessage to the corresponding service. - * - * @see_also ibus_proxy_call(), ibus_proxy_send_with_reply(), ibus_proxy_send_with_reply_and_block(). - */ -gboolean ibus_proxy_send (IBusProxy *proxy, - IBusMessage *message); - -/** - * ibus_proxy_call: - * @proxy: An IBusProxy. - * @method: The method to be called. - * @first_arg_type: Type of first argument. - * @...: Rest of arguments, NULL to mark the end. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Call a method of the corresponding service. - * - * @see_also ibus_proxy_send(), ibus_proxy_call_with_reply(), ibus_proxy_call_with_reply_and_block(). - */ -gboolean ibus_proxy_call (IBusProxy *proxy, - const gchar *method, - GType first_arg_type, - ...); - -/** - * ibus_proxy_call_with_reply: - * @proxy: An IBusProxy. - * @method: The method to be called. - * @pending: Return location of a IBusPendingCall object, or NULL if connection is disconnected. - * @timeout_milliseconds: Time out in milliseconds. - * @error: Returned error is stored here; NULL to ignore error. - * @first_arg_type: Type of first argument. - * @...: Rest of arguments, NULL to mark the end. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Call a method of the corresponding service, and returns an IBusPendingCall used to receive a reply to the message. - * This function calls ibus_connection_send_with_reply() to do the actual sending. - * - * @see_also: ibus_connection_send_with_reply(), ibus_proxy_call(), - * ibus_proxy_send_with_reply(), ibus_proxy_call_with_reply_and_block(). - */ -gboolean ibus_proxy_call_with_reply (IBusProxy *proxy, - const gchar *method, - IBusPendingCall **pending, - gint timeout_milliseconds, - IBusError **error, - GType first_arg_type, - ...); - -/** - * ibus_proxy_call_with_reply_and_block: - * @proxy: An IBusProxy. - * @method: The method to be called. - * @timeout_milliseconds: Time out in milliseconds. - * @error: Returned error is stored here; NULL to ignore error. - * @first_arg_type: Type of first argument. - * @...: Rest of arguments, NULL to mark the end. - * @returns: An IBusMessage that is the reply or NULL with an error code if the function fails. - * - * Call a method of the corresponding service and blocks a certain time period while waiting for - * an IBusMessage as reply. - * If the IBusMessage is not NULL, it calls ibus_connection_send_with_reply_and_block() to do the - * actual sending. - * - * @see_also: ibus_connection_send_with_reply_and_block(), ibus_proxy_call(), - * ibus_proxy_send_with_reply(), ibus_proxy_call_with_reply_and_block(). - */ -IBusMessage *ibus_proxy_call_with_reply_and_block - (IBusProxy *proxy, - const gchar *method, - gint timeout_milliseconds, - IBusError **error, - GType first_arg_type, - ...); - -/** - * ibus_proxy_send_with_reply: - * @proxy: An IBusProxy. - * @message: The IBusMessage to be sent. - * @pending: Return location of a IBusPendingCall object, or NULL if connection is disconnected. - * @timeout_milliseconds: Time out in milliseconds. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Send an IBusMessage to the corresponding service and returns - * an IBusPendingCall used to receive a reply to the message. - * This function calls ibus_connection_send_with_reply() to do the actual sending. - * - * @see_also: ibus_connection_send_with_reply(), ibus_proxy_send(), - * ibus_proxy_call_with_reply(), ibus_proxy_send_with_reply_and_block(). - */ -gboolean ibus_proxy_send_with_reply (IBusProxy *proxy, - IBusMessage *message, - IBusPendingCall **pending, - gint timeout_milliseconds); - -/** - * ibus_proxy_send_with_reply_and_block: - * @proxy: An IBusProxy. - * @message: The IBusMessage to be sent. - * @returns: An IBusMessage that is the reply or NULL with an error code if the function fails. - * - * Send an IBusMessage to the corresponding service and blocks a certain time period while waiting for - * an IBusMessage as reply. - * If the IBusMessage is not NULL, it calls ibus_connection_send_with_reply_and_block() to do the - * actual sending. - * - * @see_also: ibus_connection_send_with_reply_and_block(), ibus_proxy_send(), ibus_proxy_send_with_reply(), - * ibus_proxy_call_with_reply_and_block(). - */ -IBusMessage *ibus_proxy_send_with_reply_and_block - (IBusProxy *proxy, - IBusMessage *message); - -/** - * ibus_proxy_handle_signal: - * @proxy: An IBusProxy. - * @message: The IBusMessage to be sent. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Handle a signal by emitting IBusProxy::ibus-signal. - * - * If signal name is NameOwnerChanged - * and the service name is identical to the old name, then - * @proxy will be destroyed by ibus_object_destroy () and FALSE is returned. - * Otherwise TRUE is returned. - * - * Note that if the path of of message is not identical to the IBusProxy:path - * this function will not emit IBusProxy::ibus-signal. - * - */ -gboolean ibus_proxy_handle_signal (IBusProxy *proxy, - IBusMessage *message); - -/** - * ibus_proxy_get_name: - * @proxy: An IBusProxy. - * @returns: The service name of the proxy object. - * - * Get the service name of a proxy object. - */ -const gchar *ibus_proxy_get_name (IBusProxy *proxy); - -/** - * ibus_proxy_get_unique_name: - * @proxy: An IBusProxy. - * @returns: The service name of the proxy object. - * - * Get the unique name of the proxy object. - */ -const gchar *ibus_proxy_get_unique_name (IBusProxy *proxy); - -/** - * ibus_proxy_get_path: - * @proxy: An IBusProxy. - * @returns: The path of proxy object. - * - * Get the path of a proxy object. - */ -const gchar *ibus_proxy_get_path (IBusProxy *proxy); - -/** - * ibus_proxy_get_interface: - * @proxy: An IBusProxy. - * @returns: The service name of the proxy object. - * - * Get interface of a proxy object. - */ -const gchar *ibus_proxy_get_interface (IBusProxy *proxy); - -/** - * ibus_proxy_get_connection: - * @proxy: An IBusProxy. - * @returns: (transfer none): The connection of the proxy object. - * - * Get the connection of a proxy object. - */ -IBusConnection *ibus_proxy_get_connection (IBusProxy *proxy); +void ibus_proxy_destroy (IBusProxy *proxy); G_END_DECLS #endif diff --git a/src/ibusserializable.c b/src/ibusserializable.c index e4a02bc..2e4b21f 100644 --- a/src/ibusserializable.c +++ b/src/ibusserializable.c @@ -19,7 +19,6 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include "ibusinternal.h" #include "ibusserializable.h" @@ -30,7 +29,6 @@ enum { LAST_SIGNAL, }; -typedef struct _IBusSerializablePrivate IBusSerializablePrivate; struct _IBusSerializablePrivate { GData *attachments; }; @@ -38,15 +36,15 @@ struct _IBusSerializablePrivate { // static guint object_signals[LAST_SIGNAL] = { 0 }; /* functions prototype */ -static void ibus_serializable_base_init (IBusSerializableClass *klass); -static void ibus_serializable_base_fini (IBusSerializableClass *klass); -static void ibus_serializable_class_init (IBusSerializableClass *klass); +static void ibus_serializable_base_init (IBusSerializableClass *class); +static void ibus_serializable_base_fini (IBusSerializableClass *class); +static void ibus_serializable_class_init (IBusSerializableClass *class); static void ibus_serializable_init (IBusSerializable *object); static void ibus_serializable_destroy (IBusSerializable *object); static gboolean ibus_serializable_real_serialize (IBusSerializable *object, - IBusMessageIter *iter); -static gboolean ibus_serializable_real_deserialize (IBusSerializable *object, - IBusMessageIter *iter); + GVariantBuilder *builder); +static gint ibus_serializable_real_deserialize (IBusSerializable *object, + GVariant *variant); static gboolean ibus_serializable_real_copy (IBusSerializable *dest, const IBusSerializable *src); @@ -86,55 +84,44 @@ ibus_serializable_new (void) } static void -ibus_serializable_base_init (IBusSerializableClass *klass) +ibus_serializable_base_init (IBusSerializableClass *class) { - /* init signature */ - klass->signature = g_string_new ("a{sv}"); } static void -ibus_serializable_base_fini (IBusSerializableClass *klass) +ibus_serializable_base_fini (IBusSerializableClass *class) { - /* init signature */ - g_string_free (klass->signature, TRUE); - klass->signature = NULL; } static void -ibus_serializable_class_init (IBusSerializableClass *klass) +ibus_serializable_class_init (IBusSerializableClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); - parent_class = (IBusObjectClass *) g_type_class_peek_parent (klass); + parent_class = (IBusObjectClass *) g_type_class_peek_parent (class); - g_type_class_add_private (klass, sizeof (IBusSerializablePrivate)); + g_type_class_add_private (class, sizeof (IBusSerializablePrivate)); object_class->destroy = (IBusObjectDestroyFunc) ibus_serializable_destroy; - klass->serialize = ibus_serializable_real_serialize; - klass->deserialize = ibus_serializable_real_deserialize; - klass->copy = ibus_serializable_real_copy; + class->serialize = ibus_serializable_real_serialize; + class->deserialize = ibus_serializable_real_deserialize; + class->copy = ibus_serializable_real_copy; } static void -ibus_serializable_init (IBusSerializable *object) +ibus_serializable_init (IBusSerializable *serializable) { - IBusSerializablePrivate *priv; - priv = IBUS_SERIALIZABLE_GET_PRIVATE (object); - - priv->attachments = NULL; - g_datalist_init (&priv->attachments); + serializable->priv = IBUS_SERIALIZABLE_GET_PRIVATE (serializable); + serializable->priv->attachments = NULL; + g_datalist_init (&serializable->priv->attachments); } static void -ibus_serializable_destroy (IBusSerializable *object) +ibus_serializable_destroy (IBusSerializable *serializable) { - IBusSerializablePrivate *priv; - priv = IBUS_SERIALIZABLE_GET_PRIVATE (object); - - g_datalist_clear (&priv->attachments); - - parent_class->destroy (IBUS_OBJECT (object)); + g_datalist_clear (&serializable->priv->attachments); + parent_class->destroy (IBUS_OBJECT (serializable)); } static GValue * @@ -156,51 +143,28 @@ ibus_g_value_free (GValue *value) g_slice_free (GValue, value); } -static gboolean -_g_value_serialize (GValue *value, - IBusMessageIter *iter) +static GVariant * +_g_value_serialize (GValue *value) { - gboolean retval; GType type; type = G_VALUE_TYPE (value); g_return_val_if_fail (type != G_TYPE_INVALID, FALSE); - if (g_type_is_a (type, IBUS_TYPE_SERIALIZABLE)) { IBusSerializable *object; object = IBUS_SERIALIZABLE (g_value_get_object (value)); - retval = ibus_message_iter_append (iter, - type, - &object); - g_return_val_if_fail (retval, FALSE); - return TRUE; + return ibus_serializable_serialize (object); } typedef const gchar *gstring; switch (type) { -#define CASE_ENTRY(TYPE, _type, signature) \ - case G_TYPE_##TYPE: \ - { \ - g##_type v; \ - IBusMessageIter variant_iter; \ - \ - retval = ibus_message_iter_open_container (iter, \ - IBUS_TYPE_VARIANT, \ - signature, \ - &variant_iter); \ - g_return_val_if_fail (retval, FALSE); \ - \ - v = g_value_get_##_type (value); \ - retval = ibus_message_iter_append (&variant_iter, \ - G_TYPE_##TYPE, \ - &v); \ - g_return_val_if_fail (retval, FALSE); \ - \ - retval = ibus_message_iter_close_container (iter, &variant_iter); \ - g_return_val_if_fail (retval, FALSE); \ - \ - return TRUE; \ +#define CASE_ENTRY(TYPE, _type, signature) \ + case G_TYPE_##TYPE: \ + { \ + g##_type v; \ + v = g_value_get_##_type (value); \ + return g_variant_new ("v", g_variant_new (signature, v)); \ } CASE_ENTRY(CHAR, char, "y"); CASE_ENTRY(BOOLEAN, boolean, "b"); @@ -214,28 +178,19 @@ _g_value_serialize (GValue *value, #undef CASE_ENTRY } - g_return_val_if_reached (FALSE); + g_assert_not_reached (); } static GValue * -_g_value_deserialize (IBusMessageIter *iter) +_g_value_deserialize (GVariant *variant) { - IBusMessageIter variant_iter; - gboolean retval; GValue *value = NULL; - GType type; + const GVariantType *type; - retval = ibus_message_iter_recurse (iter, IBUS_TYPE_VARIANT, &variant_iter); - g_return_val_if_fail (retval, NULL); - - type = ibus_message_iter_get_arg_type (&variant_iter); - - if (type == IBUS_TYPE_STRUCT) { + type = g_variant_get_type (variant); + if (type == G_VARIANT_TYPE_TUPLE) { IBusSerializable *object; - retval = ibus_message_iter_get (iter, IBUS_TYPE_SERIALIZABLE, &object); - g_return_val_if_fail (retval, NULL); - ibus_message_iter_next (iter); - + object = ibus_serializable_deserialize (variant); value = g_slice_new0 (GValue); g_value_init (value, G_OBJECT_TYPE (object)); g_value_take_object (value, object); @@ -243,124 +198,69 @@ _g_value_deserialize (IBusMessageIter *iter) } typedef gchar *gstring; - switch (type) { -#define CASE_ENTRY(TYPE, _type) \ - case G_TYPE_##TYPE: \ - { \ - g##_type v; \ - ibus_message_iter_get_basic (&variant_iter, &v); \ - ibus_message_iter_next (&variant_iter); \ - value = g_slice_new0 (GValue); \ - g_value_init (value, G_TYPE_##TYPE); \ - g_value_set_##_type (value, v); \ - ibus_message_iter_next (iter); \ - return value; \ - } - CASE_ENTRY(CHAR, char); - CASE_ENTRY(BOOLEAN, boolean); - CASE_ENTRY(INT, int); - CASE_ENTRY(UINT, uint); - CASE_ENTRY(INT64, int64); - CASE_ENTRY(UINT64, uint64); - CASE_ENTRY(FLOAT, float); - CASE_ENTRY(DOUBLE, double); - CASE_ENTRY(STRING, string); +#define IF_ENTRY(TYPE, _type, signature) \ + if (type == G_VARIANT_TYPE_##TYPE) { \ + g##_type v; \ + g_variant_get (variant, signature, &v); \ + value = g_slice_new0 (GValue); \ + g_value_init (value, G_TYPE_##TYPE); \ + g_value_set_##_type (value, v); \ + return value; \ } +#define G_VARIANT_TYPE_CHAR G_VARIANT_TYPE_BYTE + IF_ENTRY(CHAR, char, "y"); +#undef G_VARIANT_TYPE_CHAR + IF_ENTRY(BOOLEAN, boolean, "b"); +#define G_VARIANT_TYPE_INT G_VARIANT_TYPE_INT32 +#define G_VARIANT_TYPE_UINT G_VARIANT_TYPE_UINT32 + IF_ENTRY(INT, int, "i"); + IF_ENTRY(UINT, uint, "u"); +#undef G_VARIANT_TYPE_INT +#undef G_VARIANT_TYPE_UINT + IF_ENTRY(INT64, int64, "x"); + IF_ENTRY(UINT64, uint64, "t"); + IF_ENTRY(DOUBLE, double, "d"); + IF_ENTRY(STRING, string, "s"); + g_return_val_if_reached (NULL); } static void _serialize_cb (GQuark key, GValue *value, - IBusMessageIter *iter) + GVariantBuilder *array) { - IBusMessageIter dict_entry; - gboolean retval; - const gchar *name; - - retval = ibus_message_iter_open_container (iter, - IBUS_TYPE_DICT_ENTRY, - NULL, - &dict_entry); - g_return_if_fail (retval); - name = g_quark_to_string (key); - retval = ibus_message_iter_append (&dict_entry, - G_TYPE_STRING, - &name); - g_return_if_fail (retval); - - retval = _g_value_serialize (value, &dict_entry); - g_return_if_fail (retval); - - retval = ibus_message_iter_close_container (iter, &dict_entry); - g_return_if_fail (retval); + g_variant_builder_add (array, "{sv}", + g_quark_to_string (key), _g_value_serialize (value)); } static gboolean -ibus_serializable_real_serialize (IBusSerializable *object, - IBusMessageIter *iter) +ibus_serializable_real_serialize (IBusSerializable *serializable, + GVariantBuilder *builder) { - IBusSerializablePrivate *priv; - IBusMessageIter array_iter; - gboolean retval; - - priv = IBUS_SERIALIZABLE_GET_PRIVATE (object); - - retval = ibus_message_iter_open_container (iter, - IBUS_TYPE_ARRAY, - "{sv}", - &array_iter); - g_return_val_if_fail (retval, FALSE); + GVariantBuilder array; + g_variant_builder_init (&array, G_VARIANT_TYPE ("a{sv}")); - g_datalist_foreach (&priv->attachments, + g_datalist_foreach (&serializable->priv->attachments, (GDataForeachFunc) _serialize_cb, - &array_iter); - - retval = ibus_message_iter_close_container (iter, &array_iter); - g_return_val_if_fail (retval, FALSE); - + &array); + g_variant_builder_add (builder, "a{sv}", &array); return TRUE; } -static gboolean +static gint ibus_serializable_real_deserialize (IBusSerializable *object, - IBusMessageIter *iter) + GVariant *variant) { - IBusMessageIter array_iter; - gboolean retval; - - retval = ibus_message_iter_recurse (iter, - IBUS_TYPE_ARRAY, - &array_iter); - g_return_val_if_fail (retval, FALSE); - - while (ibus_message_iter_get_arg_type (&array_iter) != G_TYPE_INVALID) { - gchar *name; - GValue *value; - IBusMessageIter dict_entry; - - retval = ibus_message_iter_recurse (&array_iter, - IBUS_TYPE_DICT_ENTRY, - &dict_entry); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_get (&dict_entry, - G_TYPE_STRING, - &name); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (&dict_entry); - - value = _g_value_deserialize (&dict_entry); - g_return_val_if_fail (value != NULL, FALSE); - - ibus_serializable_set_attachment (object, name, value); - - ibus_message_iter_next (&array_iter); + const gchar *key; + GVariant *value; + GVariantIter *iter = NULL; + g_variant_get_child (variant, 1, "a{sv}", &iter); + while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) { + ibus_serializable_set_attachment (object, key, _g_value_deserialize (value)); } - - ibus_message_iter_next (iter); - - return TRUE; + g_variant_iter_free (iter); + return 2; } static void @@ -433,31 +333,25 @@ ibus_serializable_set_qattachment (IBusSerializable *object, } const GValue * -ibus_serializable_get_qattachment (IBusSerializable *object, +ibus_serializable_get_qattachment (IBusSerializable *serializable, GQuark key) { - g_return_val_if_fail (IBUS_IS_SERIALIZABLE (object), NULL); + g_return_val_if_fail (IBUS_IS_SERIALIZABLE (serializable), NULL); g_return_val_if_fail (key != 0, NULL); - IBusSerializablePrivate *priv; - priv = IBUS_SERIALIZABLE_GET_PRIVATE (object); - - return (const GValue *) g_datalist_id_get_data (&priv->attachments, key); + return (const GValue *) g_datalist_id_get_data (&serializable->priv->attachments, key); } void -ibus_serializable_remove_qattachment (IBusSerializable *object, +ibus_serializable_remove_qattachment (IBusSerializable *serializable, GQuark key) { - g_return_if_fail (IBUS_IS_SERIALIZABLE (object)); + g_return_if_fail (IBUS_IS_SERIALIZABLE (serializable)); g_return_if_fail (key != 0); - IBusSerializablePrivate *priv; - priv = IBUS_SERIALIZABLE_GET_PRIVATE (object); - - g_datalist_id_remove_no_notify (&priv->attachments, key); + g_datalist_id_remove_no_notify (&serializable->priv->attachments, key); } IBusSerializable * @@ -481,92 +375,49 @@ ibus_serializable_copy (IBusSerializable *object) g_return_val_if_reached (NULL); } -gboolean -ibus_serializable_serialize (IBusSerializable *object, - IBusMessageIter *iter) +GVariant * +ibus_serializable_serialize (IBusSerializable *object) { g_return_val_if_fail (IBUS_IS_SERIALIZABLE (object), FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - - IBusMessageIter variant_iter; - IBusMessageIter sub_iter; gboolean retval; - gchar *signature; - - signature = g_strdup_printf ("(s%s)", IBUS_SERIALIZABLE_GET_CLASS (object)->signature->str); - retval = ibus_message_iter_open_container (iter, - IBUS_TYPE_VARIANT, - signature, - &variant_iter); - g_free (signature); - g_return_val_if_fail (retval, FALSE); + GVariantBuilder builder; + g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE); - retval = ibus_message_iter_open_container (&variant_iter, - IBUS_TYPE_STRUCT, - NULL, - &sub_iter); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (&builder, "s", g_type_name (G_OBJECT_TYPE (object))); + retval = IBUS_SERIALIZABLE_GET_CLASS (object)->serialize (object, &builder); + g_assert (retval); - const gchar *type_name = g_type_name (G_OBJECT_TYPE (object)); - g_return_val_if_fail (type_name != NULL, FALSE); - - retval = ibus_message_iter_append (&sub_iter, - G_TYPE_STRING, - &type_name); - g_return_val_if_fail (retval, FALSE); - - retval = IBUS_SERIALIZABLE_GET_CLASS (object)->serialize (object, &sub_iter); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_close_container (&variant_iter, &sub_iter); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_close_container (iter, &variant_iter); - g_return_val_if_fail (retval, FALSE); - - return TRUE; + return g_variant_builder_end (&builder); } IBusSerializable * -ibus_serializable_deserialize (IBusMessageIter *iter) +ibus_serializable_deserialize (GVariant *variant) { - g_return_val_if_fail (iter != NULL, NULL); - - gboolean retval; - IBusMessageIter variant_iter; - IBusMessageIter sub_iter; - gchar *type_name; - GType type; - IBusSerializable *object; - - type = ibus_message_iter_get_arg_type (iter); - - if (type == IBUS_TYPE_VARIANT) { - retval = ibus_message_iter_recurse (iter, IBUS_TYPE_VARIANT, &variant_iter); - g_return_val_if_fail (retval, NULL); - - retval = ibus_message_iter_recurse (&variant_iter, IBUS_TYPE_STRUCT, &sub_iter); - g_return_val_if_fail (retval, NULL); - } - else if (type == IBUS_TYPE_STRUCT) { - retval = ibus_message_iter_recurse (iter, IBUS_TYPE_STRUCT, &sub_iter); - g_return_val_if_fail (retval, NULL); - } - else + g_return_val_if_fail (variant != NULL, NULL); + + GVariant *var = NULL; + switch (g_variant_classify (variant)) { + case G_VARIANT_CLASS_VARIANT: + var = g_variant_get_variant (variant); + break; + case G_VARIANT_CLASS_TUPLE: + var = g_variant_ref (variant); + break; + default: g_return_val_if_reached (NULL); + } - retval = ibus_message_iter_get (&sub_iter, G_TYPE_STRING, &type_name); - g_return_val_if_fail (retval, NULL); - ibus_message_iter_next (&sub_iter); - - type = g_type_from_name (type_name); + gchar *type_name = NULL; + g_variant_get_child (var, 0, "&s", &type_name); + GType type = g_type_from_name (type_name); g_return_val_if_fail (g_type_is_a (type, IBUS_TYPE_SERIALIZABLE), NULL); - object = g_object_new (type, NULL); + IBusSerializable *object = g_object_new (type, NULL); - retval = IBUS_SERIALIZABLE_GET_CLASS (object)->deserialize (object, &sub_iter); + gint retval = IBUS_SERIALIZABLE_GET_CLASS (object)->deserialize (object, var); + g_variant_unref (var); if (retval) return object; diff --git a/src/ibusserializable.h b/src/ibusserializable.h index ea6bf00..358af32 100644 --- a/src/ibusserializable.h +++ b/src/ibusserializable.h @@ -19,6 +19,11 @@ * 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: ibusserializable * @short_description: A serializable object. @@ -47,7 +52,6 @@ #define __IBUS_SERIALIZABLE_H_ #include "ibusobject.h" -#include "ibusmessage.h" /* * Type macros. @@ -106,6 +110,7 @@ G_BEGIN_DECLS typedef struct _IBusSerializable IBusSerializable; typedef struct _IBusSerializableClass IBusSerializableClass; +typedef struct _IBusSerializablePrivate IBusSerializablePrivate; /** * IBusSerializable: @@ -114,9 +119,10 @@ typedef struct _IBusSerializableClass IBusSerializableClass; * private to the #IBusSerializable and should never be accessed directly. */ struct _IBusSerializable { - GObject parent; - /* instance members */ - guint32 flags; + /*< private >*/ + IBusObject parent; + IBusSerializablePrivate *priv; + /* instance members */ }; /** @@ -131,7 +137,7 @@ struct _IBusSerializable { * Return TRUE if succeed. */ typedef gboolean (* IBusSerializableSerializeFunc) (IBusSerializable *object, - IBusMessageIter *iter); + GVariantBuilder *builder); /** * IBusSerializableDeserializeFunc: @@ -143,8 +149,8 @@ typedef gboolean (* IBusSerializableSerializeFunc) (IBusSerializable * Deserialize function convert an IBusMessageIter to IBusSerializable. * Returns a gboolean value which indicates whether the conversion is success. */ -typedef gboolean (* IBusSerializableDeserializeFunc) (IBusSerializable *object, - IBusMessageIter *iter); +typedef gint (* IBusSerializableDeserializeFunc) (IBusSerializable *object, + GVariant *variant); /** * IBusSerializableCopyFunc: @@ -159,16 +165,14 @@ typedef gboolean (* IBusSerializableDeserializeFunc) (IBusSerializable typedef gboolean (* IBusSerializableCopyFunc) (IBusSerializable *dest, const IBusSerializable *src); struct _IBusSerializableClass { + /*< private >*/ IBusObjectClass parent; - /* signature */ - GString *signature; - /* virtual table */ gboolean (* serialize) (IBusSerializable *object, - IBusMessageIter *iter); - gboolean (* deserialize) (IBusSerializable *object, - IBusMessageIter *iter); + GVariantBuilder *builder); + gint (* deserialize) (IBusSerializable *object, + GVariant *variant); gboolean (* copy) (IBusSerializable *dest, const IBusSerializable *src); /*< private >*/ @@ -250,8 +254,7 @@ IBusSerializable *ibus_serializable_copy (IBusSerializable *obj * * @see_also: IBusSerializableCopyFunc(). */ -gboolean ibus_serializable_serialize (IBusSerializable *object, - IBusMessageIter *iter); +GVariant *ibus_serializable_serialize (IBusSerializable *object); /** * ibus_serializable_deserialize: @@ -263,7 +266,7 @@ gboolean ibus_serializable_serialize (IBusSerializable *obj * * @see_also: IBusSerializableCopyFunc(). */ -IBusSerializable *ibus_serializable_deserialize (IBusMessageIter *iter); +IBusSerializable *ibus_serializable_deserialize (GVariant *variant); G_END_DECLS #endif diff --git a/src/ibusserver.c b/src/ibusserver.c index 60b250c..97ae35b 100644 --- a/src/ibusserver.c +++ b/src/ibusserver.c @@ -87,19 +87,19 @@ ibus_server_listen (IBusServer *server, } static void -ibus_server_class_init (IBusServerClass *klass) +ibus_server_class_init (IBusServerClass *class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (class); - g_type_class_add_private (klass, sizeof (IBusServerPrivate)); + g_type_class_add_private (class, sizeof (IBusServerPrivate)); gobject_class->set_property = (GObjectSetPropertyFunc) ibus_server_set_property; gobject_class->get_property = (GObjectGetPropertyFunc) ibus_server_get_property; ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_server_destroy; - klass->new_connection = ibus_server_new_connection; + class->new_connection = ibus_server_new_connection; /* install properties */ /** @@ -131,7 +131,7 @@ ibus_server_class_init (IBusServerClass *klass) */ server_signals[NEW_CONNECTION] = g_signal_new (I_("new-connection"), - G_TYPE_FROM_CLASS (klass), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IBusServerClass, new_connection), NULL, NULL, diff --git a/src/ibusservice.c b/src/ibusservice.c index 2d044d0..8cec154 100644 --- a/src/ibusservice.c +++ b/src/ibusservice.c @@ -19,177 +19,276 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include #include "ibusservice.h" #include "ibusinternal.h" #define IBUS_SERVICE_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_SERVICE, IBusServicePrivate)) +/* XXX */ enum { - IBUS_MESSAGE, - IBUS_SIGNAL, - LAST_SIGNAL, + LAST_SIGNAL }; enum { PROP_0, - PROP_PATH + PROP_OBJECT_PATH, + PROP_CONNECTION, }; -/* IBusServicePriv */ +/* IBusServicePrivate */ struct _IBusServicePrivate { - gchar *path; - GList *connections; + gchar *object_path; + GDBusConnection *connection; + GHashTable *table; + gboolean constructed; }; -typedef struct _IBusServicePrivate IBusServicePrivate; -static guint service_signals[LAST_SIGNAL] = { 0 }; +/* +static guint service_signals[LAST_SIGNAL] = { 0 }; +*/ /* functions prototype */ -static void ibus_service_destroy (IBusService *service); -static void ibus_service_set_property (IBusService *service, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void ibus_service_get_property (IBusService *service, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static gboolean ibus_service_ibus_message (IBusService *service, - IBusConnection *connection, - IBusMessage *message); -static gboolean ibus_service_ibus_signal (IBusService *service, - IBusConnection *connection, - IBusMessage *message); - -G_DEFINE_TYPE (IBusService, ibus_service, IBUS_TYPE_OBJECT) +static void ibus_service_base_init (IBusServiceClass *class); +static void ibus_service_base_fini (IBusServiceClass *class); +static void ibus_service_class_init (IBusServiceClass *class); +static void ibus_service_init (IBusService *service); +static void ibus_service_constructed (GObject *object); +static void ibus_service_set_property (IBusService *service, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void ibus_service_get_property (IBusService *service, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void ibus_service_destroy (IBusService *service); +static void ibus_service_service_method_call + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation + *invocation); +static GVariant *ibus_service_service_get_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error); +static gboolean ibus_service_service_set_property + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error); +static void ibus_service_service_method_call_cb + (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation + *invocation, + IBusService *service); +static GVariant *ibus_service_service_get_property_cb + (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error, + IBusService *service); +static gboolean ibus_service_service_set_property_cb + (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error, + IBusService *service); +static void ibus_service_connection_closed_cb + (GDBusConnection *connection, + gboolean remote_peer_vanished, + GError *error, + IBusService *service); +static void ibus_service_unregister_cb (GDBusConnection *connection, + guint *ids, + IBusService *service); + +static const GDBusInterfaceVTable ibus_service_interface_vtable = { + (GDBusInterfaceMethodCallFunc) ibus_service_service_method_call_cb, + (GDBusInterfaceGetPropertyFunc) ibus_service_service_get_property_cb, + (GDBusInterfaceSetPropertyFunc) ibus_service_service_set_property_cb +}; -IBusService * -ibus_service_new (const gchar *path) +static IBusObjectClass *ibus_service_parent_class = NULL; + +GType +ibus_service_get_type (void) { - GObject *obj; - obj = g_object_new (IBUS_TYPE_SERVICE, - "path", path, - NULL); - return IBUS_SERVICE (obj); + static GType type = 0; + + static const GTypeInfo type_info = { + sizeof (IBusServiceClass), + (GBaseInitFunc) ibus_service_base_init, + (GBaseFinalizeFunc) ibus_service_base_fini, + (GClassInitFunc) ibus_service_class_init, + NULL, /* class finialize */ + NULL, /* class data */ + sizeof (IBusService), + 0, + (GInstanceInitFunc) ibus_service_init, + }; + + if (type == 0) { + type = g_type_register_static (IBUS_TYPE_OBJECT, + "IBusService", + &type_info, + 0); + } + + return type; +} + +static void +ibus_service_base_init (IBusServiceClass *class) +{ + GArray *old = class->interfaces; + class->interfaces = g_array_new (TRUE, TRUE, sizeof (GDBusInterfaceInfo *)); + if (old != NULL) { + GDBusInterfaceInfo **p = (GDBusInterfaceInfo **)old->data; + while (*p != NULL) { + g_array_append_val (class->interfaces, *p++); + } + } +} + +static void +ibus_service_base_fini (IBusServiceClass *class) +{ + GDBusInterfaceInfo **interfaces = (GDBusInterfaceInfo **) g_array_free (class->interfaces, FALSE); + GDBusInterfaceInfo **p = interfaces; + while (*p != NULL) { + g_dbus_interface_info_unref (*p++); + } + g_free (interfaces); } +static const gchar introspection_xml[] = + "" + " " + " " + " " + ""; + static void -ibus_service_class_init (IBusServiceClass *klass) +ibus_service_class_init (IBusServiceClass *class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (class); - g_type_class_add_private (klass, sizeof (IBusServicePrivate)); + ibus_service_parent_class = IBUS_OBJECT_CLASS (g_type_class_peek_parent (class)); + gobject_class->constructed = ibus_service_constructed; gobject_class->set_property = (GObjectSetPropertyFunc) ibus_service_set_property; gobject_class->get_property = (GObjectGetPropertyFunc) ibus_service_get_property; - ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_service_destroy; + ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_service_destroy; - klass->ibus_message = ibus_service_ibus_message; - klass->ibus_signal = ibus_service_ibus_signal; + /* virtual functions */ + class->service_method_call = ibus_service_service_method_call; + class->service_get_property = ibus_service_service_get_property; + class->service_set_property = ibus_service_service_set_property; + + /* class members */ + ibus_service_class_add_interfaces (class, introspection_xml); /* install properties */ /** - * IBusService:path: + * IBusService:object-path: * * The path of service object. */ g_object_class_install_property ( gobject_class, - PROP_PATH, + PROP_OBJECT_PATH, g_param_spec_string ( - "path", + "object-path", "object path", "The path of service object", NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY) + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_NAME | + G_PARAM_STATIC_NICK | + G_PARAM_STATIC_BLURB) ); - - /* Install signals */ /** - * IBusService::ibus-message: - * @service: An IBusService. - * @connection: Corresponding IBusConnection. - * @message: An IBusMessage to be sent. - * - * Send a message as IBusMessage though the @connection. + * IBusService:connection: * - * Returns: TRUE if succeed; FALSE otherwise. - * Argument @user_data is ignored in this function. + * The connection of service object. */ - service_signals[IBUS_MESSAGE] = - g_signal_new (I_("ibus-message"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (IBusServiceClass, ibus_message), - NULL, NULL, - ibus_marshal_BOOLEAN__POINTER_POINTER, - G_TYPE_BOOLEAN, - 2, - G_TYPE_POINTER, - G_TYPE_POINTER); - - /** - * IBusService::ibus-signal: - * @service: An IBusService. - * @connection: Corresponding IBusConnection. - * @message: An IBusMessage to be sent. - * - * Send a signal as IBusMessage though the @connection. - * - * Returns: TRUE if succeed; FALSE otherwise. - * Argument @user_data is ignored in this function. - */ - service_signals[IBUS_SIGNAL] = - g_signal_new (I_("ibus-signal"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (IBusServiceClass, ibus_signal), - NULL, NULL, - ibus_marshal_BOOLEAN__POINTER_POINTER, - G_TYPE_BOOLEAN, - 2, - G_TYPE_POINTER, - G_TYPE_POINTER); + g_object_class_install_property ( + gobject_class, + PROP_CONNECTION, + g_param_spec_object ( + "connection", + "connection", + "The connection of service object", + G_TYPE_DBUS_CONNECTION, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_NAME | + G_PARAM_STATIC_NICK | + G_PARAM_STATIC_BLURB) + ); + g_type_class_add_private (class, sizeof (IBusServicePrivate)); } static void ibus_service_init (IBusService *service) { - IBusServicePrivate *priv; - priv = IBUS_SERVICE_GET_PRIVATE (service); - - priv->path = NULL; - priv->connections = NULL; + service->priv = IBUS_SERVICE_GET_PRIVATE (service); + service->priv->table = g_hash_table_new (NULL, NULL); } static void -ibus_service_destroy (IBusService *service) +ibus_service_constructed (GObject *object) { - IBusServicePrivate *priv; - priv = IBUS_SERVICE_GET_PRIVATE (service); - - ibus_service_remove_from_all_connections (service); - - g_free (priv->path); - priv->path = NULL; - - IBUS_OBJECT_CLASS(ibus_service_parent_class)->destroy (IBUS_OBJECT (service)); + IBusService *service = (IBusService *)object; + if (service->priv->connection) { + GError *error = NULL; + if (!ibus_service_register (service, service->priv->connection, &error)) { + g_debug ("%s", error->message); + g_error_free (error); + } + } + service->priv->constructed = TRUE; } static void -ibus_service_set_property (IBusService *service, - guint prop_id, const GValue *value, GParamSpec *pspec) +ibus_service_set_property (IBusService *service, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - IBusServicePrivate *priv; - priv = IBUS_SERVICE_GET_PRIVATE (service); - switch (prop_id) { - case PROP_PATH: - priv->path = g_strdup (g_value_get_string (value)); + case PROP_OBJECT_PATH: + service->priv->object_path = g_value_dup_string (value); + break; + case PROP_CONNECTION: + service->priv->connection = g_value_dup_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (service, prop_id, pspec); @@ -198,204 +297,331 @@ ibus_service_set_property (IBusService *service, static void ibus_service_get_property (IBusService *service, - guint prop_id, GValue *value, GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { switch (prop_id) { - case PROP_PATH: - g_value_set_string (value, ibus_service_get_path (service)); + case PROP_OBJECT_PATH: + g_value_set_string (value, service->priv->object_path); + break; + case PROP_CONNECTION: + g_value_set_object (value, service->priv->connection); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (service, prop_id, pspec); } } -const gchar * -ibus_service_get_path (IBusService *service) +static void +ibus_service_destroy (IBusService *service) { - g_assert (IBUS_IS_SERVICE (service)); + g_free (service->priv->object_path); + service->priv->object_path = NULL; + + if (service->priv->connection) { + g_object_unref (service->priv->connection); + service->priv->connection = NULL; + } - IBusServicePrivate *priv; - priv = IBUS_SERVICE_GET_PRIVATE (service); + if (service->priv->table) { + g_hash_table_foreach_remove (service->priv->table, + (GHRFunc)ibus_service_unregister_cb, service); + g_hash_table_destroy (service->priv->table); + service->priv->table = NULL; + } - return priv->path; + IBUS_OBJECT_CLASS(ibus_service_parent_class)->destroy (IBUS_OBJECT (service)); } -gboolean -ibus_service_handle_message (IBusService *service, - IBusConnection *connection, - IBusMessage *message) + +static void +ibus_service_service_method_call (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation) { - gboolean retval = FALSE; - g_return_val_if_fail (message != NULL, FALSE); + if (g_strcmp0 (method_name, "Destroy") == 0) { + g_dbus_method_invocation_return_value (invocation, NULL); + ibus_object_destroy ((IBusObject *)service); + return; + } - g_signal_emit (service, service_signals[IBUS_MESSAGE], 0, connection, message, &retval); - return retval; + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_UNKNOWN_METHOD, + "%s::%s", interface_name, method_name); + return; } -static gboolean -ibus_service_ibus_message (IBusService *service, - IBusConnection *connection, - IBusMessage *message) +static GVariant * +ibus_service_service_get_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error) { - if (ibus_message_is_method_call (message, "", "Destroy")) { - IBusMessage *reply; - reply = ibus_message_new_method_return (message); - ibus_connection_send (connection, reply); - ibus_message_unref (reply); - return TRUE; - } - return FALSE; + return NULL; } static gboolean -ibus_service_ibus_signal (IBusService *service, - IBusConnection *connection, - IBusMessage *message) +ibus_service_service_set_property (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error) { return FALSE; } - -gboolean -_service_message_function (IBusConnection *connection, - IBusMessage *message, - IBusService *service) +static void +ibus_service_service_method_call_cb (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + IBusService *service) { - return ibus_service_handle_message (service, connection, message); + IBUS_SERVICE_GET_CLASS (service)->service_method_call (service, + connection, + sender, + object_path, + interface_name, + method_name, + parameters, + invocation); } -static void -_connection_destroy_cb (IBusConnection *connection, IBusService *service) +static GVariant * +ibus_service_service_get_property_cb (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error, + IBusService *service) { - g_assert (IBUS_IS_CONNECTION (connection)); - g_assert (IBUS_IS_SERVICE (service)); - - ibus_service_remove_from_connection (service, connection); + return IBUS_SERVICE_GET_CLASS (service)->service_get_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + error); } -gboolean -ibus_service_add_to_connection (IBusService *service, IBusConnection *connection) +static gboolean +ibus_service_service_set_property_cb (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error, + IBusService *service) { - g_assert (IBUS_IS_SERVICE (service)); - g_assert (IBUS_IS_CONNECTION (connection)); - - gboolean retval; - IBusServicePrivate *priv; - priv = IBUS_SERVICE_GET_PRIVATE (service); - - g_return_val_if_fail (priv->path != NULL, FALSE); - g_return_val_if_fail (g_list_find (priv->connections, connection) == NULL, FALSE); + return IBUS_SERVICE_GET_CLASS (service)->service_set_property (service, + connection, + sender, + object_path, + interface_name, + property_name, + value, + error); +} - g_object_ref_sink (connection); +static void +ibus_service_connection_closed_cb (GDBusConnection *connection, + gboolean remote_peer_vanished, + GError *error, + IBusService *service) +{ + ibus_service_unregister (service, connection); + if (connection == service->priv->connection) { + ibus_object_destroy ((IBusObject *) service); + } +} - retval = ibus_connection_register_object_path (connection, priv->path, - (IBusMessageFunc) _service_message_function, service); - if (!retval) { - g_object_unref (connection); - return FALSE; +static void +ibus_service_unregister_cb (GDBusConnection *connection, + guint *ids, + IBusService *service) +{ + guint *p = ids; + while (*p != 0) { + g_dbus_connection_unregister_object (connection, *p++); } + g_signal_handlers_disconnect_by_func (connection, + G_CALLBACK (ibus_service_connection_closed_cb), service); + g_object_unref (connection); + g_free (ids); +} - priv->connections = g_list_append (priv->connections, connection); - g_signal_connect (connection, - "destroy", - (GCallback) _connection_destroy_cb, - service); +IBusService * +ibus_service_new (GDBusConnection *connection, + const gchar *object_path) +{ + g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); + g_return_val_if_fail (object_path != NULL, NULL); - return retval; + GObject *obj = g_object_new (IBUS_TYPE_SERVICE, + "object-path", object_path, + "connection", connection, + NULL); + return IBUS_SERVICE (obj); } -GList * -ibus_service_get_connections (IBusService *service) +const gchar * +ibus_service_get_object_path (IBusService *service) { - g_assert (IBUS_IS_SERVICE (service)); - - IBusServicePrivate *priv; - priv = IBUS_SERVICE_GET_PRIVATE (service); + g_return_val_if_fail (IBUS_IS_SERVICE (service), NULL); + return service->priv->object_path; +} - return g_list_copy (priv->connections); +GDBusConnection * +ibus_service_get_connection (IBusService *service) +{ + g_return_val_if_fail (IBUS_IS_SERVICE (service), NULL); + return service->priv->connection; } gboolean -ibus_service_remove_from_connection (IBusService *service, IBusConnection *connection) +ibus_service_register (IBusService *service, + GDBusConnection *connection, + GError **error) { g_return_val_if_fail (IBUS_IS_SERVICE (service), FALSE); - g_return_val_if_fail (IBUS_IS_CONNECTION (connection), FALSE); + g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE); + g_return_val_if_fail (connection != service->priv->connection || service->priv->constructed == FALSE, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + GArray *array = NULL; + + if (g_hash_table_lookup (service->priv->table, connection)) { + if (error) { + *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_OBJECT_PATH_IN_USE, + "Service %p has been registered with connection %p.", + service, connection); + } + goto error_out; + } - IBusServicePrivate *priv; - priv = IBUS_SERVICE_GET_PRIVATE (service); + GDBusInterfaceInfo **p = (GDBusInterfaceInfo **)IBUS_SERVICE_GET_CLASS (service)->interfaces->data; + if (*p == NULL) { + if (error) { + *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Service %p does not have any interface.", + service); + } + goto error_out; + } - g_assert (priv->path != NULL); - g_assert (g_list_find (priv->connections, connection) != NULL); + array = g_array_new (TRUE, TRUE, sizeof (guint)); + while (*p != NULL) { + guint id = g_dbus_connection_register_object (connection, + service->priv->object_path, + *p, + &ibus_service_interface_vtable, + g_object_ref (service), + (GDestroyNotify)g_object_unref, + error); + if (id != 0) { + g_array_append_val (array, id); + } + else { + g_object_unref (service); + goto error_out; + } + p++; + } - gboolean retval; - retval = ibus_connection_unregister_object_path (connection, priv->path); + g_signal_connect (connection, "closed", + G_CALLBACK (ibus_service_connection_closed_cb), service); + g_hash_table_insert (service->priv->table, + g_object_ref (connection), g_array_free (array, FALSE)); + return TRUE; - if (!retval) { - return FALSE; +error_out: + if (array != NULL) { + guint *ids = (guint*) array->data; + while (*ids != 0) { + g_dbus_connection_unregister_object (connection, *ids++); + } + g_array_free (array, TRUE); } + return FALSE; +} - g_signal_handlers_disconnect_by_func (connection, - (GCallback) _connection_destroy_cb, - service); - priv->connections = g_list_remove (priv->connections, connection); - g_object_unref (connection); +void +ibus_service_unregister (IBusService *service, + GDBusConnection *connection) +{ + g_return_if_fail (IBUS_IS_SERVICE (service)); + g_return_if_fail (G_IS_DBUS_CONNECTION (connection)); - return TRUE; + guint *ids = (guint *) g_hash_table_lookup (service->priv->table, connection); + g_return_if_fail (ids != NULL); + + ibus_service_unregister_cb (connection, ids, service); + g_hash_table_remove (service->priv->table, connection); } gboolean -ibus_service_remove_from_all_connections (IBusService *service) +ibus_service_emit_signal (IBusService *service, + const gchar *dest_bus_name, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + GError **error) { g_return_val_if_fail (IBUS_IS_SERVICE (service), FALSE); - - IBusServicePrivate *priv; - priv = IBUS_SERVICE_GET_PRIVATE (service); - - GList *element = priv->connections; - while (element != NULL) { - IBusConnection *connection = IBUS_CONNECTION (element->data); - - gboolean retval; - retval = ibus_connection_unregister_object_path (connection, priv->path); - - g_signal_handlers_disconnect_by_func (connection, - (GCallback) _connection_destroy_cb, - service); - g_object_unref (connection); - element = element->next; - } - - g_list_free (priv->connections); - priv->connections = NULL; - return TRUE; + g_return_val_if_fail (interface_name != NULL, FALSE); + g_return_val_if_fail (signal_name != NULL, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + g_return_val_if_fail (service->priv->connection != NULL, FALSE); + + return g_dbus_connection_emit_signal (service->priv->connection, + dest_bus_name, + service->priv->object_path, + interface_name, + signal_name, + parameters, + error); } gboolean -ibus_service_send_signal (IBusService *service, - const gchar *interface, - const gchar *name, - GType first_arg_type, - ...) +ibus_service_class_add_interfaces (IBusServiceClass *class, + const gchar *xml_data) { - g_assert (IBUS_IS_SERVICE (service)); - g_assert (name != NULL); - - gboolean retval; - va_list args; - GList *p; - - IBusServicePrivate *priv; - priv = IBUS_SERVICE_GET_PRIVATE (service); - - for (p = priv->connections; p != NULL; p = p->next) { - va_start (args, first_arg_type); - retval = ibus_connection_send_signal_valist ((IBusConnection *) p->data, - priv->path, - interface, - name, - first_arg_type, - args); - va_end (args); + g_return_val_if_fail (IBUS_IS_SERVICE_CLASS (class), FALSE); + g_return_val_if_fail (xml_data != NULL, FALSE); + + GError *error = NULL; + GDBusNodeInfo *introspection_data = g_dbus_node_info_new_for_xml (xml_data, &error); + if (introspection_data == NULL) { + g_debug ("%s", error->message); + g_error_free (error); + return FALSE; + } + else { + GDBusInterfaceInfo **p = introspection_data->interfaces; + while (*p != NULL) { + g_dbus_interface_info_ref (*p); + g_array_append_val (class->interfaces, *p); + p++; + } + // g_dbus_node_info_unref (introspection_data); + return TRUE; } - return retval; } diff --git a/src/ibusservice.h b/src/ibusservice.h index 6e1b870..7a3fea7 100644 --- a/src/ibusservice.h +++ b/src/ibusservice.h @@ -19,6 +19,11 @@ * 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: ibusservice * @short_description: IBus service back-end. @@ -30,8 +35,8 @@ #ifndef __IBUS_SERVICE_H_ #define __IBUS_SERVICE_H_ +#include #include "ibusobject.h" -#include "ibusconnection.h" /* * Type macros. @@ -55,6 +60,7 @@ G_BEGIN_DECLS typedef struct _IBusService IBusService; typedef struct _IBusServiceClass IBusServiceClass; +typedef struct _IBusServicePrivate IBusServicePrivate; /** * IBusService: @@ -62,49 +68,49 @@ typedef struct _IBusServiceClass IBusServiceClass; * An opaque data type representing an IBusService. */ struct _IBusService { + /*< private >*/ IBusObject parent; - /* instance members */ + IBusServicePrivate *priv; }; -/** - * ServiceIBusMessageFunc: - * @service: An IBsService. - * @connection: Connection to IBus daemon. - * @message: IBusMessage to be sent. - * @returns: %TRUE if succeed; %FALSE if failed. - * - * Prototype of IBus service message sending callback function. - */ -typedef gboolean (* ServiceIBusMessageFunc) (IBusService *service, - IBusConnection *connection, - IBusMessage *message); - -/** - * ServiceIBusSignalFunc: - * @service: An IBsService. - * @connection: Connection to IBus daemon. - * @message: IBusMessage to be sent. - * @returns: %TRUE if succeed; %FALSE if failed. - * - * Prototype of IBus service signal sending callback function. - */ -typedef gboolean (* ServiceIBusSignalFunc) (IBusService *service, - IBusConnection *connection, - IBusMessage *message); - struct _IBusServiceClass { + /*< private >*/ IBusObjectClass parent; - /* signals */ - gboolean (* ibus_message) (IBusService *service, - IBusConnection *connection, - IBusMessage *message); - gboolean (* ibus_signal) (IBusService *service, - IBusConnection *connection, - IBusMessage *message); + /*< public >*/ + /* virtual functions */ + void (* service_method_call) + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation + *invocation); + GVariant * (* service_get_property) + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error); + gboolean (* service_set_property) + (IBusService *service, + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error); /*< private >*/ + GArray *interfaces; + /* padding */ - gpointer pdummy[6]; + gpointer pdummy[4]; }; @@ -117,74 +123,49 @@ GType ibus_service_get_type (void); * * New an IBusService. */ -IBusService *ibus_service_new (const gchar *path); - +IBusService *ibus_service_new (GDBusConnection *connection, + const gchar *path); /** - * ibus_service_get_path: + * ibus_service_get_object_path: * @service: An IBusService. * @returns: The object path of @service * * Returns the object path of an IBusService. */ -const gchar *ibus_service_get_path (IBusService *service); +const gchar *ibus_service_get_object_path (IBusService *service); /** - * ibus_service_handle_message: + * ibus_service_get_connections: * @service: An IBusService. - * @connection: Corresponding IBusCOnnection - * @message: IBusMessage to be handled. - * @returns: TRUE if succeed; FALSE otherwise. + * @returns: (transfer all) (element-type GDBusConnection): A newly allocated list of connections. * - * Emit an IBusMessage on an IBusConnection. + * Returns a connections. */ -gboolean ibus_service_handle_message (IBusService *service, - IBusConnection *connection, - IBusMessage *message); +GDBusConnection *ibus_service_get_connection (IBusService *service); /** - * ibus_service_add_to_connection: + * ibus_service_register: * @service: An IBusService. - * @connection: Corresponding IBusCOnnection - * @returns: TRUE if succeed; FALSE otherwise. + * @connection: A GDBusConnection the service will be registered to. + * @error: Return location for error or NULL. + * @returns: TRUE if the service was registered, FALSE otherwise. * - * Add an IBus Service to an IBusConnection. - * This function also connects the service to the signal IBusConnection::destroy of the connection. + * Registers service to a connection. */ -gboolean ibus_service_add_to_connection (IBusService *service, - IBusConnection *connection); - +gboolean ibus_service_register (IBusService *service, + GDBusConnection *connection, + GError **error); /** - * ibus_service_get_connections: + * ibus_service_unregister: * @service: An IBusService. - * @returns: (transfer container) (element-type IBusConnection): A newly allocated list of connections. + * @connection: A GDBusConnection the service was registered with. * - * Returns a copy of list of connections, but the caller does not own the element. + * Unregisters service from a connection. */ -GList *ibus_service_get_connections (IBusService *service); +void ibus_service_unregister (IBusService *service, + GDBusConnection *connection); -/** - * ibus_service_remove_from_connection: - * @service: An IBusService. - * @connection: Corresponding IBusCOnnection - * @returns: TRUE if succeed; FALSE otherwise. - * - * Remove an IBusService from an IBusConnection. - * This function also disconnects the signal IBusConnection::destroy. - */ -gboolean ibus_service_remove_from_connection - (IBusService *service, - IBusConnection *connection); -/** - * ibus_service_remove_from_all_connections: - * @service: An IBusService. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Remove an IBusService from all connections. - * This function also disconnects the signal IBusConnection::destroy. - */ -gboolean ibus_service_remove_from_all_connections - (IBusService *service); /** * ibus_service_send_signal: @@ -197,13 +178,27 @@ gboolean ibus_service_remove_from_all_connections * * Send signal to all the IBusConnections of an IBusService. * - * @see_also: ibus_connection_send_signal() + * @see_also: g_dbus_connection_emit_signal() + */ +gboolean ibus_service_emit_signal (IBusService *service, + const gchar *dest_bus_name, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + GError **error); +/** + * ibus_service_class_add_interfaces: + * @klass: An IBusServiceClass. + * @xml_data: The introspection xml data. + * @error: Error. + * + * Set the interface introspection information with the service class. */ -gboolean ibus_service_send_signal (IBusService *service, - const gchar *interface, - const gchar *name, - GType first_arg_type, - ...); +gboolean ibus_service_class_add_interfaces + (IBusServiceClass *klass, + const gchar *xml_data); + + G_END_DECLS #endif diff --git a/src/ibusshare.c b/src/ibusshare.c index b942009..f4feb39 100644 --- a/src/ibusshare.c +++ b/src/ibusshare.c @@ -20,6 +20,7 @@ * Boston, MA 02111-1307, USA. */ +#include "ibusshare.h" #include #include #include @@ -29,8 +30,7 @@ #include #include #include -#include -#include "ibusshare.h" +#include static gchar *_display = NULL; @@ -40,9 +40,18 @@ ibus_get_local_machine_id (void) static gchar *machine_id = NULL; if (machine_id == NULL) { - gchar *id = dbus_get_local_machine_id (); - machine_id = g_strdup (id); - dbus_free (id); + GError *error = NULL; + if (!g_file_get_contents ("/var/lib/dbus/machine-id", + &machine_id, + NULL, + &error)) { + g_warning ("Unable to load /var/lib/dbus/machine-id: %s", error->message); + g_error_free (error); + machine_id = "machine-id"; + } + else { + g_strstrip (machine_id); + } } return machine_id; @@ -287,6 +296,12 @@ void ibus_init (void) { g_type_init (); + IBUS_TYPE_TEXT; + IBUS_TYPE_ATTRIBUTE; + IBUS_TYPE_ATTR_LIST; + IBUS_TYPE_LOOKUP_TABLE; + IBUS_TYPE_COMPONENT; + IBUS_TYPE_ENGINE_DESC; } static GMainLoop *main_loop = NULL; diff --git a/src/ibusshare.h b/src/ibusshare.h index ed6a4af..a9e37a8 100644 --- a/src/ibusshare.h +++ b/src/ibusshare.h @@ -19,6 +19,11 @@ * 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. diff --git a/src/ibustext.c b/src/ibustext.c index 96985b6..b63cbc9 100644 --- a/src/ibustext.c +++ b/src/ibustext.c @@ -24,29 +24,27 @@ /* functions prototype */ static void ibus_text_destroy (IBusText *text); static gboolean ibus_text_serialize (IBusText *text, - IBusMessageIter *iter); -static gboolean ibus_text_deserialize (IBusText *text, - IBusMessageIter *iter); + GVariantBuilder *builder); +static int ibus_text_deserialize (IBusText *text, + GVariant *variant); static gboolean ibus_text_copy (IBusText *dest, const IBusText *src); G_DEFINE_TYPE (IBusText, ibus_text, IBUS_TYPE_SERIALIZABLE) static void -ibus_text_class_init (IBusTextClass *klass) +ibus_text_class_init (IBusTextClass *class) { - IBusObjectClass *object_class = IBUS_OBJECT_CLASS (klass); - IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (klass); + IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class); + IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class); - ibus_text_parent_class = (IBusSerializableClass *) g_type_class_peek_parent (klass); + ibus_text_parent_class = (IBusSerializableClass *) g_type_class_peek_parent (class); object_class->destroy = (IBusObjectDestroyFunc) ibus_text_destroy; serializable_class->serialize = (IBusSerializableSerializeFunc) ibus_text_serialize; serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_text_deserialize; serializable_class->copy = (IBusSerializableCopyFunc) ibus_text_copy; - - g_string_append (serializable_class->signature, "sv"); } static void @@ -75,57 +73,47 @@ ibus_text_destroy (IBusText *text) static gboolean ibus_text_serialize (IBusText *text, - IBusMessageIter *iter) + GVariantBuilder *builder) { gboolean retval; retval = IBUS_SERIALIZABLE_CLASS (ibus_text_parent_class)->serialize ( - (IBusSerializable *)text, iter); + (IBusSerializable *)text, builder); g_return_val_if_fail (retval, FALSE); - retval = ibus_message_iter_append (iter, G_TYPE_STRING, &text->text); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "s", text->text); if (text->attrs == NULL) { text->attrs = ibus_attr_list_new (); g_object_ref_sink (text->attrs); } - - retval = ibus_message_iter_append (iter, IBUS_TYPE_ATTR_LIST, &text->attrs); - g_return_val_if_fail (retval, FALSE); + g_variant_builder_add (builder, "v", ibus_serializable_serialize ((IBusSerializable *)text->attrs)); return TRUE; } -static gboolean -ibus_text_deserialize (IBusText *text, - IBusMessageIter *iter) +static gint +ibus_text_deserialize (IBusText *text, + GVariant *variant) { - gboolean retval; - gchar *str; - + gint retval; retval = IBUS_SERIALIZABLE_CLASS (ibus_text_parent_class)->deserialize ( - (IBusSerializable *)text, iter); - g_return_val_if_fail (retval, FALSE); - - retval = ibus_message_iter_get (iter, G_TYPE_STRING, &str); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); + (IBusSerializable *)text, variant); + if (text->is_static == FALSE) + g_free (text->text); + g_variant_get_child (variant, retval++, "s", &text->text); text->is_static = FALSE; - text->text = g_strdup (str); - if (text->attrs) { + if (text->attrs) g_object_unref (text->attrs); - text->attrs = NULL; - } - retval = ibus_message_iter_get (iter, IBUS_TYPE_ATTR_LIST, &text->attrs); + GVariant *var = g_variant_get_child_value (variant, retval++); + text->attrs = IBUS_ATTR_LIST (ibus_serializable_deserialize (var)); + g_variant_unref (var); g_object_ref_sink (text->attrs); - g_return_val_if_fail (retval, FALSE); - ibus_message_iter_next (iter); - return TRUE; + return retval; } static gboolean diff --git a/src/ibustext.h b/src/ibustext.h index c340681..246e5ab 100644 --- a/src/ibustext.h +++ b/src/ibustext.h @@ -19,6 +19,11 @@ * 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: ibustext * @short_description: Text with decorating information. diff --git a/src/ibustypes.h b/src/ibustypes.h index 23ae0de..035d124 100644 --- a/src/ibustypes.h +++ b/src/ibustypes.h @@ -19,6 +19,11 @@ * 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: ibustypes * @short_description: Generic types for IBus. diff --git a/src/ibusxml.h b/src/ibusxml.h index 2e975de..ff5e65e 100644 --- a/src/ibusxml.h +++ b/src/ibusxml.h @@ -19,6 +19,11 @@ * 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: ibusxml * @short_description: XML handling functions for IBus. diff --git a/src/test-attribute.c b/src/test-attribute.c deleted file mode 100644 index 7fe16fb..0000000 --- a/src/test-attribute.c +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ -#include "ibus.h" -#include "stdio.h" - -int main() -{ - g_type_init (); - IBusAttrList *list; - IBusMessage *message; - gboolean retval; - IBusError *error; - - list = ibus_attr_list_new (); - ibus_attr_list_append (list, ibus_attribute_new (1, 1, 1, 2)); - ibus_attr_list_append (list, ibus_attribute_new (2, 1, 1, 2)); - ibus_attr_list_append (list, ibus_attribute_new (3, 1, 1, 2)); - ibus_attr_list_append (list, ibus_attribute_new (3, 1, 1, 2)); - - message = ibus_message_new_signal ("/org/freedesktop/IBus", - "org.freedesktop.IBus", - "Test"); - - IBusSerializable *p = ibus_serializable_new (); - retval = ibus_message_append_args (message, - IBUS_TYPE_SERIALIZABLE, &p, - IBUS_TYPE_SERIALIZABLE, &p, - IBUS_TYPE_SERIALIZABLE, &p, - IBUS_TYPE_SERIALIZABLE, &p, - IBUS_TYPE_SERIALIZABLE, &p, - G_TYPE_INVALID); - g_assert (retval); - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_SERIALIZABLE, &p, - IBUS_TYPE_SERIALIZABLE, &p, - IBUS_TYPE_SERIALIZABLE, &p, - IBUS_TYPE_SERIALIZABLE, &p, - IBUS_TYPE_SERIALIZABLE, &p, - G_TYPE_INVALID); - g_assert (retval); - - return 0; - -} diff --git a/src/test-bus.c b/src/test-bus.c deleted file mode 100644 index 3cb3937..0000000 --- a/src/test-bus.c +++ /dev/null @@ -1,102 +0,0 @@ -/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ -#include -#include "ibus.h" - -static gchar * -get_last_engine_id (const GList *engines) -{ - g_assert (engines); - const char *result = NULL; - for (; engines; engines = g_list_next (engines)) { - IBusEngineDesc *engine_desc = IBUS_ENGINE_DESC (engines->data); - g_assert (engine_desc); - result = engine_desc->name; - } - g_assert (result); - return g_strdup (result); -} - -static void -print_engines (const GList *engines) -{ - g_assert (engines); - for (; engines; engines = g_list_next (engines)) { - IBusEngineDesc *engine_desc = IBUS_ENGINE_DESC (engines->data); - g_assert (engine_desc); - g_debug ("%s (id:%s, icon:%s)", engine_desc->longname, engine_desc->name, engine_desc->icon); - g_object_unref (engine_desc); - } -} - -int main() -{ - g_type_init (); - - IBusBus *bus; - GList *engines; - gchar *active_engine_name; - - bus = ibus_bus_new (); - - /* Test ibusbus.c */ - g_debug ("===== Active engines:"); - engines = ibus_bus_list_active_engines (bus); - g_assert (engines); - active_engine_name = get_last_engine_id (engines); - print_engines (engines); - g_list_free (engines); - - g_debug ("===== All engines:"); - engines = ibus_bus_list_engines (bus); - g_assert (engines); - print_engines (engines); - g_list_free (engines); - - g_debug ("===== Global engine:"); - if (ibus_bus_get_use_global_engine (bus)) { - g_debug ("use_global_engine is true."); - if (ibus_bus_is_global_engine_enabled (bus)) { - g_debug ("Global engine is enabled."); - IBusEngineDesc *global_engine = ibus_bus_get_global_engine (bus); - g_assert (global_engine); - g_debug ("%s (id:%s, icon:%s)", global_engine->longname, - global_engine->name, global_engine->icon); - g_object_unref (global_engine); - } - } - - g_debug ("===== Use system layout:%s", ibus_bus_get_use_sys_layout (bus) ? "true" : "false"); - - g_debug ("Test ibusbus.c: passed."); - - /* Test ibusinputcontext.c */ -#if 1 - { - IBusInputContext *context; - IBusEngineDesc *engine_desc; - gchar *current_ic; - context = ibus_bus_create_input_context (bus, "test"); - ibus_input_context_set_capabilities (context, IBUS_CAP_FOCUS); - ibus_input_context_disable (context); - g_assert (ibus_input_context_is_enabled (context) == FALSE); - ibus_input_context_enable (context); - g_assert (ibus_input_context_is_enabled (context) == TRUE); - ibus_input_context_focus_in (context); - ibus_input_context_set_engine (context, active_engine_name); - current_ic = ibus_bus_current_input_context (bus); - g_assert (!strcmp (current_ic, ibus_proxy_get_path (IBUS_PROXY (context)))); - engine_desc = ibus_input_context_get_engine (context); - g_assert (engine_desc); - g_assert (!strcmp (active_engine_name, engine_desc->name)); - g_debug ("Test ibusinputcontext.c: passed."); - - g_free (active_engine_name); - g_free (current_ic); - g_object_unref (engine_desc); - g_object_unref (context); - } -#endif - g_object_unref (bus); - - return 0; -} diff --git a/src/test-keynames.c b/src/test-keynames.c deleted file mode 100644 index 5176acf..0000000 --- a/src/test-keynames.c +++ /dev/null @@ -1,9 +0,0 @@ -/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ -#include "ibus.h" - -int main() -{ - g_assert_cmpstr (ibus_keyval_name (IBUS_Home), ==, "Home"); - g_assert (ibus_keyval_from_name ("Home") == IBUS_Home); - return 0; -} diff --git a/src/test-lookuptable.c b/src/test-lookuptable.c deleted file mode 100644 index e094a2d..0000000 --- a/src/test-lookuptable.c +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ -#include -#include "ibus.h" - -int main() -{ - g_type_init (); - IBusLookupTable *table, *table1; - IBusMessage *message; - IBusError *error; - gboolean retval; - - table = ibus_lookup_table_new (9, 0, TRUE, FALSE); - ibus_lookup_table_append_candidate (table, ibus_text_new_from_static_string ("Hello")); - ibus_lookup_table_append_candidate (table, ibus_text_new_from_static_string ("Cool")); - - message = ibus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); - - retval = ibus_message_append_args (message, - IBUS_TYPE_LOOKUP_TABLE, &table, - IBUS_TYPE_LOOKUP_TABLE, &table, - G_TYPE_INVALID); - g_assert (retval); - - g_object_unref (table); - table = table1 = NULL; - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_LOOKUP_TABLE, &table, - IBUS_TYPE_LOOKUP_TABLE, &table1, - G_TYPE_INVALID); - g_assert (retval); - g_assert (table); - g_assert (table1); - - g_object_unref (table); - g_object_unref (table1); - - return 0; -} diff --git a/src/test-text.c b/src/test-text.c deleted file mode 100644 index f8a8ea1..0000000 --- a/src/test-text.c +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ -#include "ibus.h" - -int main() -{ - g_type_init (); - - IBusText *text1; - IBusText *text2; - IBusMessage *message; - IBusError *error; - gboolean retval; - - text1 = ibus_text_new_from_string ("Hello"); - text2 = ibus_text_new_from_static_string ("Hello"); - - message = ibus_message_new_signal ("/org/freedesktop/IBus", - "org.freedesktop.IBus", - "Test"); - - retval = ibus_message_append_args (message, - IBUS_TYPE_SERIALIZABLE, &text1, - IBUS_TYPE_SERIALIZABLE, &text2, - G_TYPE_INVALID); - g_assert (retval); - g_object_unref (text1); - g_object_unref (text2); - - retval = ibus_message_get_args (message, - &error, - IBUS_TYPE_SERIALIZABLE, &text1, - IBUS_TYPE_SERIALIZABLE, &text2, - G_TYPE_INVALID); - g_assert (retval); - g_assert_cmpstr (text1->text, ==, "Hello"); - g_assert_cmpstr (text2->text, ==, "Hello"); - - g_object_unref (text1); - g_object_unref (text2); - - return 0; - -} diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am new file mode 100644 index 0000000..6d35868 --- /dev/null +++ b/src/tests/Makefile.am @@ -0,0 +1,65 @@ +# vim:set noet ts=4: +# +# ibus - The Input Bus +# +# Copyright (c) 2007-2010 Peng Huang +# Copyright (c) 2007-2010 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 +# 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 + +NULL = + +INCLUDES = \ + -g \ + @GLIB2_CFLAGS@ \ + @GIO2_CFLAGS@ \ + -I$(top_srcdir)/src \ + $(NULL) + +prog_ldadd = \ + @GLIB2_LIBS@ \ + @GIO2_LIBS@ \ + $(top_builddir)/src/libibus-2.0.la \ + $(NULL) + +noinst_PROGRAMS = $(TESTS) +TESTS = \ + ibus-bus \ + ibus-keynames \ + ibus-serializable \ + ibus-share \ + ibus-factory \ + ibus-configservice\ + $(NULL) + +ibus_bus_SOURCES = ibus-bus.c +ibus_bus_LDADD = $(prog_ldadd) + +ibus_keynames_SOURCES = ibus-keynames.c +ibus_keynames_LDADD = $(prog_ldadd) + +ibus_serializable_SOURCES = ibus-serializable.c +ibus_serializable_LDADD = $(prog_ldadd) + +ibus_share_SOURCES = ibus-share.c +ibus_share_CFLAGS = @DBUS_CFLAGS@ +ibus_share_LDADD = $(prog_ldadd) @DBUS_LIBS@ + +ibus_factory_SOURCES = ibus-factory.c +ibus_factory_LDADD = $(prog_ldadd) + +ibus_configservice_SOURCES = ibus-configservice.c +ibus_configservice_LDADD = $(prog_ldadd) diff --git a/src/tests/ibus-bus.c b/src/tests/ibus-bus.c new file mode 100644 index 0000000..dff44bc --- /dev/null +++ b/src/tests/ibus-bus.c @@ -0,0 +1,130 @@ +#include +#include "ibus.h" + +#if 0 +static gchar * +get_last_engine_id (const GList *engines) +{ + g_assert (engines); + const char *result = NULL; + for (; engines; engines = g_list_next (engines)) { + IBusEngineDesc *engine_desc = IBUS_ENGINE_DESC (engines->data); + g_assert (engine_desc); + result = engine_desc->name; + } + g_assert (result); + return g_strdup (result); +} + +static void +print_engines (const GList *engines) +{ + g_assert (engines); + for (; engines; engines = g_list_next (engines)) { + IBusEngineDesc *engine_desc = IBUS_ENGINE_DESC (engines->data); + g_assert (engine_desc); + // g_debug ("%s (id:%s, icon:%s)", engine_desc->longname, engine_desc->name, engine_desc->icon); + g_object_unref (engine_desc); + } +} + +static void +test_list_active_engines (void) +{ + GList *engines; + IBusBus *bus; + IBUS_TYPE_ENGINE_DESC; + + bus = ibus_bus_new (); + + engines = ibus_bus_list_active_engines (bus); + + g_assert (engines); + g_list_foreach (engines, (GFunc) g_object_unref, NULL); + g_list_free (engines); + g_object_unref (bus); +} + +static void +test_list_engines (void) +{ + GList *engines; + IBusBus *bus; + IBUS_TYPE_ENGINE_DESC; + + bus = ibus_bus_new (); + + engines = ibus_bus_list_engines (bus); + + g_assert (engines); + g_list_foreach (engines, (GFunc) g_object_unref, NULL); + g_list_free (engines); + g_object_unref (bus); +} +#endif + +gint +main (gint argc, + gchar **argv) +{ + g_type_init (); + g_test_init (&argc, &argv, NULL); +#if 0 + g_test_add_func ("/ibus/list-engines", test_list_engines); + g_test_add_func ("/ibus/list-active-engines", test_list_active_engines); +#endif + return g_test_run (); +#if 0 + IBusBus *bus; + GList *engines; + gchar *active_engine_name; + + bus = ibus_bus_new (); + + if (ibus_bus_get_use_global_engine (bus)) { + g_debug ("use_global_engine is true."); + if (ibus_bus_is_global_engine_enabled (bus)) { + g_debug ("Global engine is enabled."); + IBusEngineDesc *global_engine = ibus_bus_get_global_engine (bus); + g_assert (global_engine); + g_debug ("%s (id:%s, icon:%s)", global_engine->longname, + global_engine->name, global_engine->icon); + g_object_unref (global_engine); + } + } + + g_debug ("===== Use system layout:%s", ibus_bus_get_use_sys_layout (bus) ? "true" : "false"); + + g_debug ("Test ibusbus.c: passed."); + + /* Test ibusinputcontext.c */ +#if 1 + { + IBusInputContext *context; + IBusEngineDesc *engine_desc; + gchar *current_ic; + context = ibus_bus_create_input_context (bus, "test"); + ibus_input_context_set_capabilities (context, IBUS_CAP_FOCUS); + ibus_input_context_disable (context); + g_assert (ibus_input_context_is_enabled (context) == FALSE); + ibus_input_context_enable (context); + g_assert (ibus_input_context_is_enabled (context) == TRUE); + ibus_input_context_focus_in (context); + ibus_input_context_set_engine (context, active_engine_name); + current_ic = ibus_bus_current_input_context (bus); + g_assert (!strcmp (current_ic, g_dbus_proxy_get_object_path ((GDBusProxy *)context))); + engine_desc = ibus_input_context_get_engine (context); + g_assert (engine_desc); + g_assert (!strcmp (active_engine_name, engine_desc->name)); + g_debug ("Test ibusinputcontext.c: passed."); + + g_free (active_engine_name); + g_free (current_ic); + g_object_unref (engine_desc); + g_object_unref (context); + } +#endif + g_object_unref (bus); +#endif + return 0; +} diff --git a/src/tests/ibus-configservice.c b/src/tests/ibus-configservice.c new file mode 100644 index 0000000..38d500f --- /dev/null +++ b/src/tests/ibus-configservice.c @@ -0,0 +1,43 @@ +#include + +static gboolean +timeout_cb (gpointer data) +{ + g_main_loop_quit ((GMainLoop *)data); + return FALSE; +} + +static void +run_loop_with_timeout (gint interval) +{ + GMainLoop *loop = g_main_loop_new (NULL, FALSE); + g_timeout_add (interval, timeout_cb, loop); + g_main_loop_run (loop); + g_main_loop_unref (loop); +} + +static void +test_configservice (void) +{ + IBusBus *bus = ibus_bus_new (); + IBusConfigService *config = ibus_config_service_new (ibus_bus_get_connection (bus)); + ibus_bus_request_name (bus, "test.config", 0); + + run_loop_with_timeout (1000); + + g_object_unref (config); + g_object_unref (bus); +} + +gint +main (gint argc, + gchar **argv) +{ + g_mem_set_vtable (glib_mem_profiler_table); + g_type_init (); + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/ibus/configservice", test_configservice); + + return g_test_run (); +} diff --git a/src/test-engine.c b/src/tests/ibus-engine.c similarity index 100% rename from src/test-engine.c rename to src/tests/ibus-engine.c diff --git a/src/tests/ibus-factory.c b/src/tests/ibus-factory.c new file mode 100644 index 0000000..e3fa405 --- /dev/null +++ b/src/tests/ibus-factory.c @@ -0,0 +1,43 @@ +#include + +static gboolean +timeout_cb (gpointer data) +{ + g_main_loop_quit ((GMainLoop *)data); + return FALSE; +} + +static void +run_loop_with_timeout (gint interval) +{ + GMainLoop *loop = g_main_loop_new (NULL, FALSE); + g_timeout_add (interval, timeout_cb, loop); + g_main_loop_run (loop); + g_main_loop_unref (loop); +} + +static void +test_factory (void) +{ + IBusBus *bus = ibus_bus_new (); + IBusFactory *factory = ibus_factory_new (ibus_bus_get_connection (bus)); + ibus_bus_request_name (bus, "test.factory", 0); + + run_loop_with_timeout (1000); + + g_object_unref (factory); + g_object_unref (bus); +} + +gint +main (gint argc, + gchar **argv) +{ + g_mem_set_vtable (glib_mem_profiler_table); + g_type_init (); + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/ibus/factory", test_factory); + + return g_test_run (); +} diff --git a/src/test-global-engine.c b/src/tests/ibus-global-engine.c similarity index 98% rename from src/test-global-engine.c rename to src/tests/ibus-global-engine.c index cf526e6..a7cbc60 100644 --- a/src/test-global-engine.c +++ b/src/tests/ibus-global-engine.c @@ -39,6 +39,7 @@ change_global_engine_cb (IBusBus *bus) int main() { g_type_init (); + IBUS_TYPE_ENGINE_DESC; IBusBus *bus; diff --git a/src/test-keymap.c b/src/tests/ibus-keymap.c similarity index 100% rename from src/test-keymap.c rename to src/tests/ibus-keymap.c diff --git a/src/tests/ibus-keynames.c b/src/tests/ibus-keynames.c new file mode 100644 index 0000000..5ca6cc6 --- /dev/null +++ b/src/tests/ibus-keynames.c @@ -0,0 +1,20 @@ +#include "ibus.h" + +static void +test_keyname (void) +{ + g_assert_cmpstr (ibus_keyval_name (IBUS_Home), ==, "Home"); + g_assert (ibus_keyval_from_name ("Home") == IBUS_Home); +} + +gint +main (gint argc, + gchar **argv) +{ + g_type_init (); + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/ibus/keyname", test_keyname); + + return g_test_run (); +} diff --git a/src/test-proxy.c b/src/tests/ibus-proxy.c similarity index 100% rename from src/test-proxy.c rename to src/tests/ibus-proxy.c diff --git a/src/tests/ibus-serializable.c b/src/tests/ibus-serializable.c new file mode 100644 index 0000000..c2a7529 --- /dev/null +++ b/src/tests/ibus-serializable.c @@ -0,0 +1,147 @@ +#include "ibus.h" + +void g_variant_type_info_assert_no_infos (void); + +void test_serializable (IBusSerializable *object) +{ + GVariant *variant; + gchar *s1, *s2; + + variant = ibus_serializable_serialize (object); + g_object_unref (object); + g_variant_get_data (variant); + s1 = g_variant_print (variant, TRUE); + + object = (IBusSerializable *) ibus_serializable_deserialize (variant); + g_variant_unref (variant); + + variant = ibus_serializable_serialize (object); + g_object_unref (object); + g_variant_get_data (variant); + s2 = g_variant_print (variant, TRUE); + g_variant_unref (variant); + + g_assert_cmpstr (s1, ==, s2); + g_free (s1); + g_free (s2); +} + +static void +test_varianttypeinfo (void) +{ + g_variant_type_info_assert_no_infos (); +} + +static void +test_attr_list (void) +{ + IBusAttrList *list = ibus_attr_list_new (); + ibus_attr_list_append (list, ibus_attribute_new (1, 1, 1, 2)); + ibus_attr_list_append (list, ibus_attribute_new (2, 1, 1, 2)); + ibus_attr_list_append (list, ibus_attribute_new (3, 1, 1, 2)); + ibus_attr_list_append (list, ibus_attribute_new (3, 1, 1, 2)); + test_serializable ((IBusSerializable *)list); + g_variant_type_info_assert_no_infos (); +} + +static void +test_text (void) +{ + test_serializable ((IBusSerializable *)ibus_text_new_from_string ("Hello")); + test_serializable ((IBusSerializable *)ibus_text_new_from_string ("Hello")); + test_serializable ((IBusSerializable *)ibus_text_new_from_string ("Hello")); + test_serializable ((IBusSerializable *)ibus_text_new_from_string ("Hello")); + g_variant_type_info_assert_no_infos (); +} + +static void +test_engine_desc (void) +{ + test_serializable ((IBusSerializable *)ibus_engine_desc_new ("Hello", + "Hello Engine", + "Hello Engine Desc", + "zh", + "GPLv2", + "Peng Huang ", + "icon", + "en")); + g_variant_type_info_assert_no_infos (); +} + +static void +test_lookup_table (void) +{ + IBusLookupTable *table; + + table = ibus_lookup_table_new (9, 0, TRUE, FALSE); + test_serializable ((IBusSerializable *)table); + +#if 1 + table = ibus_lookup_table_new (9, 0, TRUE, FALSE); + ibus_lookup_table_append_candidate (table, ibus_text_new_from_static_string ("Hello")); + ibus_lookup_table_append_candidate (table, ibus_text_new_from_static_string ("Cool")); + test_serializable ((IBusSerializable *)table); +#endif + + table = ibus_lookup_table_new (9, 0, TRUE, FALSE); + ibus_lookup_table_append_candidate (table, ibus_text_new_from_static_string ("Hello")); + ibus_lookup_table_append_candidate (table, ibus_text_new_from_static_string ("Cool")); + ibus_lookup_table_append_label (table, ibus_text_new_from_static_string ("Hello")); + ibus_lookup_table_append_label (table, ibus_text_new_from_static_string ("Cool")); + test_serializable ((IBusSerializable *)table); + g_variant_type_info_assert_no_infos (); +} + +static void +test_property (void) +{ + IBusPropList *list = ibus_prop_list_new (); + ibus_prop_list_append (list, ibus_property_new ("sub1", + PROP_TYPE_NORMAL, + ibus_text_new_from_static_string ("label_sub1"), + "icon_sub1", + ibus_text_new_from_static_string ("tooltip_sub1"), + TRUE, + TRUE, + PROP_STATE_UNCHECKED, + NULL)); + ibus_prop_list_append (list, ibus_property_new ("sub2", + PROP_TYPE_NORMAL, + ibus_text_new_from_static_string ("label_sub1"), + "icon_sub1", + ibus_text_new_from_static_string ("tooltip_sub1"), + TRUE, + TRUE, + PROP_STATE_UNCHECKED, + NULL)); + g_object_ref (list); + test_serializable ((IBusSerializable *)list); + test_serializable ((IBusSerializable *)ibus_property_new ("key", + PROP_TYPE_NORMAL, + ibus_text_new_from_static_string ("label"), + "icon", + ibus_text_new_from_static_string ("tooltip"), + TRUE, + TRUE, + PROP_STATE_UNCHECKED, + list)); + g_variant_type_info_assert_no_infos (); +} + + +gint +main (gint argc, + gchar **argv) +{ + g_mem_set_vtable (glib_mem_profiler_table); + g_type_init (); + g_test_init (&argc, &argv, NULL); + g_test_add_func ("/ibus/varianttypeinfo", test_varianttypeinfo); + g_test_add_func ("/ibus/attrlist", test_attr_list); + g_test_add_func ("/ibus/text", test_text); + g_test_add_func ("/ibus/enginedesc", test_engine_desc); + g_test_add_func ("/ibus/lookuptable", test_lookup_table); + g_test_add_func ("/ibus/property", test_property); + + return g_test_run (); +} diff --git a/src/test-server.c b/src/tests/ibus-server.c similarity index 100% rename from src/test-server.c rename to src/tests/ibus-server.c diff --git a/src/tests/ibus-share.c b/src/tests/ibus-share.c new file mode 100644 index 0000000..332e9c5 --- /dev/null +++ b/src/tests/ibus-share.c @@ -0,0 +1,24 @@ +#include +#include + +static void +test_machine_id (void) +{ + const gchar *s1 = ibus_get_local_machine_id (); + gchar *s2 = dbus_get_local_machine_id (); + + g_assert_cmpstr (s1, ==, s2); + dbus_free (s2); +} + +gint +main (gint argc, + gchar **argv) +{ + g_mem_set_vtable (glib_mem_profiler_table); + g_type_init (); + g_test_init (&argc, &argv, NULL); + g_test_add_func ("/ibus/marchine-id", test_machine_id); + + return g_test_run (); +} -- 2.7.4