diff options
author | fujiwarat <takao.fujiwara1@gmail.com> | 2012-03-05 14:03:34 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2012-03-05 14:03:34 +0900 |
commit | 5ecd67f59c8aa8993dc6eb9afeb66c330b1eb8c8 (patch) | |
tree | fc64210b81701f5b8c30608692c01c9c73c39883 /gir | |
parent | 85e1b094985d6f8f61d324f45cf893c7c63c38b5 (diff) | |
download | ibus-anthy-5ecd67f59c8aa8993dc6eb9afeb66c330b1eb8c8.tar.gz |
Converted pygtk2 to gir gtk3.
Diffstat (limited to 'gir')
-rw-r--r-- | gir/Makefile.am | 102 | ||||
-rw-r--r-- | gir/anthygcontext.c | 237 | ||||
-rw-r--r-- | gir/anthygcontext.h | 204 | ||||
-rw-r--r-- | gir/test.c | 34 | ||||
-rw-r--r-- | gir/test.py | 18 |
5 files changed, 595 insertions, 0 deletions
diff --git a/gir/Makefile.am b/gir/Makefile.am new file mode 100644 index 0000000..1a26bf1 --- /dev/null +++ b/gir/Makefile.am @@ -0,0 +1,102 @@ +# vim:set noet ts=4: +# +# ibus-anthy - The Anthy engine for IBus +# +# Copyright (c) 2012 Takao Fujiwara <takao.fujiwara1@gmail.com> +# Copyright (c) 2012 Peng Huang <shawn.p.huang@gmail.com> +# Copyright (c) 2012 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +INTROSPECTION_GIRS = + +libanthygobject = libanthygobject-1.0.la + +AM_CPPFLAGS = \ + @GOBJECT2_CFLAGS@ \ + @ANTHY_CFLAGS@ \ + $(NULL) + +libanthygobject_LTLIBRARIES = $(libanthygobject) +libanthygobjectdir = @ANTHY_GOBJECT_LIBDIR@ + +libanthygobject_1_0_la_SOURCES = \ + anthygcontext.c \ + $(NULL) + +libanthygobject_1_0_la_LIBADD = \ + @GOBJECT2_LIBS@ \ + @ANTHY_LIBS@ \ + $(NULL) + +libanthygobject_1_0_la_LDFLAGS = \ + -no-undefined \ + -export-symbols-regex "anthy_.*" \ + -version-info @LT_VERSION_INFO@ \ + $(NULL) + +ANTHY_INCLUDEDIR = $(shell pkg-config --variable=includedir anthy) + +anthyincludedir = $(includedir)/ibus-anthy-1.0 +anthyinclude_HEADERS = \ + anthygcontext.h \ + $(NULL) + +# gobject introspection +-include $(INTROSPECTION_MAKEFILE) + +Anthy-9000.gir: $(libanthygobject) Makefile +Anthy_9000_gir_SCANNERFLAGS = \ + --pkg=anthy \ + --external-library \ + --reparse-validate \ + --identifier-prefix=Anthy \ + --symbol-prefix=anthy \ + --accept-unprefixed \ + --warn-all \ + $(NULL) +Anthy_9000_gir_INCLUDES = GObject-2.0 +Anthy_9000_gir_LIBS = $(libanthygobject) anthy +Anthy_9000_gir_CFLAGS = @ANTHY_CFLAGS@ +Anthy_9000_gir_FILES = \ + $(libanthygobject_1_0_la_SOURCES) \ + $(anthyinclude_HEADERS) \ + $(ANTHY_INCLUDEDIR)/anthy/anthy.h \ + $(NULL) +INTROSPECTION_GIRS += Anthy-9000.gir + +girdir = @ANTHY_GOBJECT_GIRDIR@ +dist_gir_DATA = $(INTROSPECTION_GIRS) + +typelibsdir = @ANTHY_GOBJECT_TYPELIBSDIR@ +typelibs_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) + +noinst_PROGRAMS = test + +test_SOURCES = test.c +test_LDADD = \ + $(libanthygobject) \ + @GOBJECT2_LIBS@ \ + @ANTHY_LIBS@ \ + $(NULL) + +CLEANFILES = \ + $(dist_gir_DATA) \ + $(typelibs_DATA) \ + $(NULL) + +DISTCLEANFILES = \ + $(NULL) + diff --git a/gir/anthygcontext.c b/gir/anthygcontext.c new file mode 100644 index 0000000..ed3d587 --- /dev/null +++ b/gir/anthygcontext.c @@ -0,0 +1,237 @@ +/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ +/* vim:set et sts=4: */ +/* ibus-anthy - The Anthy engine for IBus + * Copyright (c) 2012 Takao Fujiwara <takao.fujiwara1@gmail.com> + * Copyright (c) 2012 Peng Huang <shawn.p.huang@gmail.com> + * Copyright (c) 2012 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <glib-object.h> +#include <anthy/anthy.h> + +extern void anthy_init_personality (void); +extern int anthy_do_set_personality (const char *id); + +#include "anthygcontext.h" + +#define ANTHY_GCONTEXT_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), ANTHY_TYPE_GCONTEXT, AnthyGContextPrivate)) + +struct _AnthyGContextPrivate { + anthy_context_t context; +}; + +static GObject *anthy_gcontext_constructor (GType type, + guint n, + GObjectConstructParam *args); +static void anthy_gcontext_dispose (GObject *gobject); +static void anthy_gcontext_finalize (GObject *gobject); + +G_DEFINE_TYPE (AnthyGContext, anthy_gcontext, G_TYPE_INITIALLY_UNOWNED) + +static void +anthy_gcontext_class_init (AnthyGContextClass *class) +{ + + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + gobject_class->constructor = anthy_gcontext_constructor; + gobject_class->dispose = anthy_gcontext_dispose; + gobject_class->finalize = anthy_gcontext_finalize; + + g_type_class_add_private (class, sizeof (AnthyGContextPrivate)); +} + +static void +anthy_gcontext_init (AnthyGContext *obj) +{ + obj->priv = ANTHY_GCONTEXT_GET_PRIVATE (obj); + + anthy_init (); + obj->priv->context = anthy_create_context (); +} + +static GObject * +anthy_gcontext_constructor (GType type, + guint n, + GObjectConstructParam *args) +{ + GObject *object; + + object = G_OBJECT_CLASS (anthy_gcontext_parent_class)->constructor (type, n ,args); + return object; +} + +static void +anthy_gcontext_dispose (GObject *gobject) +{ + G_OBJECT_CLASS (anthy_gcontext_parent_class)->dispose (gobject); +} + +static void +anthy_gcontext_finalize (GObject *gobject) +{ + G_OBJECT_CLASS (anthy_gcontext_parent_class)->finalize (gobject); +} + +AnthyGContext * +anthy_gcontext_new (void) +{ + GObject *gobject = g_object_new (ANTHY_TYPE_GCONTEXT, NULL); + return ANTHY_GCONTEXT (gobject); +} + +#define ANTHY_OBJECT_FUNCTION_ASSERTIONS() \ +{ \ + g_assert (obj != NULL); \ + g_assert (obj->priv != NULL); \ + g_assert (obj->priv->context != NULL); \ +} + +int +anthy_gcontext_set_encoding (AnthyGContext *obj, int encoding) +{ + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + return anthy_context_set_encoding (obj->priv->context, encoding); +} + +void +anthy_gcontext_init_personality (AnthyGContext *obj) +{ + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + anthy_init_personality (); +} + +int +anthy_gcontext_do_set_personality (AnthyGContext *obj, const gchar *dict_name) +{ + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + return anthy_do_set_personality (dict_name); +} + +void +anthy_gcontext_resize_segment (AnthyGContext *obj, + int nth, + int resize) +{ + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + anthy_resize_segment (obj->priv->context, nth, resize); +} + +int +anthy_gcontext_set_string (AnthyGContext *obj, const gchar * string) +{ + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + return anthy_set_string (obj->priv->context, string); +} + +int +anthy_gcontext_get_nr_segments (AnthyGContext *obj) +{ + struct anthy_conv_stat conv_stat = { 0, }; + + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + anthy_get_stat(obj->priv->context, &conv_stat); + return conv_stat.nr_segment; +} + +gchar * +anthy_gcontext_get_segment (AnthyGContext *obj, int nth_seg, int nth_lookup) +{ + int length; + static char temp[512]; + + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + length = anthy_get_segment (obj->priv->context, nth_seg, nth_lookup, + temp, sizeof (temp)); + if (length >= 0) { + return g_strdup (temp); + } else { + return NULL; + } +} + +int +anthy_gcontext_commit_segment(AnthyGContext *obj, int nth_seg, int nth_lookup) +{ + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + return anthy_commit_segment (obj->priv->context, nth_seg, nth_lookup); +} + +int +anthy_gcontext_get_nr_candidates (AnthyGContext *obj, int nth_seg) +{ + struct anthy_segment_stat seg_stat = { 0, }; + + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + anthy_get_segment_stat (obj->priv->context, nth_seg, &seg_stat); + return seg_stat.nr_candidate; +} + +int +anthy_gcontext_set_prediction_string (AnthyGContext *obj, const gchar * string) +{ + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + return anthy_set_prediction_string (obj->priv->context, string); +} + +int +anthy_gcontext_get_nr_predictions (AnthyGContext *obj) +{ + struct anthy_prediction_stat seg_stat = { 0, }; + + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + anthy_get_prediction_stat (obj->priv->context, &seg_stat); + return seg_stat.nr_prediction; +} + +gchar * +anthy_gcontext_get_prediction (AnthyGContext *obj, int nth_seg) +{ + int length; + static char temp[512]; + + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + length = anthy_get_prediction (obj->priv->context, nth_seg, + temp, sizeof (temp)); + if (length >= 0) { + return g_strdup (temp); + } else { + return NULL; + } +} + +int +anthy_gcontext_commit_prediction (AnthyGContext *obj, int nth_seg) +{ + ANTHY_OBJECT_FUNCTION_ASSERTIONS (); + + return anthy_commit_prediction (obj->priv->context, nth_seg); +} + +#undef ANTHY_OBJECT_FUNCTION_ASSERTIONS diff --git a/gir/anthygcontext.h b/gir/anthygcontext.h new file mode 100644 index 0000000..93c4538 --- /dev/null +++ b/gir/anthygcontext.h @@ -0,0 +1,204 @@ +/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ +/* vim:set et sts=4: */ +/* ibus-anthy - The Anthy engine for IBus + * Copyright (c) 2012 Takao Fujiwara <takao.fujiwara1@gmail.com> + * Copyright (c) 2012 Peng Huang <shawn.p.huang@gmail.com> + * Copyright (c) 2012 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __ANTHY_GCONTEXT_H_ +#define __ANTHY_GCONTEXT_H_ + +#include <glib-object.h> +#include <anthy/anthy.h> + +/* + * Type macros. + */ +#define ANTHY_TYPE_GCONTEXT \ + (anthy_gcontext_get_type ()) +#define ANTHY_GCONTEXT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANTHY_TYPE_GCONTEXT, AnthyGContext)) +#define ANTHY_GCONTEXT_CLASS(class) \ + (G_TYPE_CHECK_CLASS_CAST ((class), ANTHY_TYPE_GCONTEXT, AnthyGContextClass)) +#define ANTHY_IS_GCONTEXT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ANTHY_TYPE_GCONTEXT)) +#define ANTHY_IS_GCONTEXT_CLASS(class) \ + (G_TYPE_CHECK_CLASS_TYPE ((class), ANTHY_TYPE_GCONTEXT)) +#define ANTHY_GCONTEXT_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), ANTHY_TYPE_GCONTEXT, AnthyGContextClass)) + +typedef struct _AnthyGContext AnthyGContext; +typedef struct _AnthyGContextPrivate AnthyGContextPrivate; +typedef struct _AnthyGContextClass AnthyGContextClass; + +G_BEGIN_DECLS + +/** + * AnthyGContext: + * + * An #AnthyGContext is an object that handles conversion strings. + */ +struct _AnthyGContext { + GInitiallyUnowned parent; + + AnthyGContextPrivate *priv; + + /*< private >*/ + gpointer pdummy[8]; +}; + +struct _AnthyGContextClass { + GInitiallyUnownedClass parent; + + /*< private >*/ + gpointer pdummy[8]; +}; + +GType anthy_gcontext_get_type (void); + +/** + * anthy_gcontext_new: + * @returns: A newly allocated #AnthyGContext + * + * New an #AnthyGobject. + */ +AnthyGContext *anthy_gcontext_new (void); + +/** + * anthy_gcontext_set_encoding: + * @encoding: An encoding + * + * Set an encoding. + */ +int anthy_gcontext_set_encoding (AnthyGContext *obj, + int encoding); + +/** + * anthy_gcontext_init_personality: + * + * Initialize the personal dictionaries. + */ +void anthy_gcontext_init_personality (AnthyGContext *obj); + +/** + * anthy_gcontext_do_set_personality: + * @dict_name: a Dictionary name + * + * Set a personal dictionary. + */ +int anthy_gcontext_do_set_personality (AnthyGContext *obj, + const gchar *dict_name); + +/** + * anthy_gcontext_resize_segment: + * @nth: nth segment + * @resize: size + * + * Resize the nth segment. + */ +void anthy_gcontext_resize_segment (AnthyGContext *obj, + int nth, + int resize); +/** + * anthy_gcontext_set_string: + * @string: A conversion string + * + * Set a conversion string. + */ +int anthy_gcontext_set_string (AnthyGContext *obj, + const gchar * string); +/** + * anthy_gcontext_get_nr_segments: + * @returns: The number of the converted segments + * + * The number of the converted segments + */ +int anthy_gcontext_get_nr_segments (AnthyGContext *obj); + +/** + * anthy_gcontext_get_segment: + * @nth_seg: Nth segment + * @nth_lookup: Nth lookup + * @returns: A newly assigned string. + * + * A newly assigned string with @ntg_seg and @nth_lookup . + */ +gchar * anthy_gcontext_get_segment (AnthyGContext *obj, + int nth_seg, + int nth_lookup); + +/** + * anthy_gcontext_commit_segment: + * @nth_seg: Nth segment + * @nth_lookup: Nth lookup + * + * Commit a string with @ntg_seg and @nth_lookup. + */ +int anthy_gcontext_commit_segment (AnthyGContext *obj, + int nth_seg, + int nth_lookup); + +/** + * anthy_gcontext_get_nr_candidates: + * @returns: The number of the candidates + * + * The number of the candidates + */ +int anthy_gcontext_get_nr_candidates (AnthyGContext *obj, + int nth_seg); + +/** + * anthy_gcontext_set_prediction_string: + * @string: A prediction string + * + * Set a prediction string. + */ +int anthy_gcontext_set_prediction_string + (AnthyGContext *obj, + const gchar * string); + +/** + * anthy_gcontext_get_nr_predictions: + * @returns: The number of the converted segments in the current + * prediction string. + * + * The number of the converted segments in the current prediction string. + */ +int anthy_gcontext_get_nr_predictions + (AnthyGContext *obj); + +/** + * anthy_gcontext_get_prediction: + * @nth_seg: Nth segment + * @returns: A newly assigned string. + * + * A newly assigned string with @ntg_seg . + */ +gchar * anthy_gcontext_get_prediction (AnthyGContext *obj, + int nth_seg); + +/** + * anthy_gcontext_commit_prediction: + * @nth_seg: Nth segment + * + * Commit a prediction string with @ntg_seg . + */ +int anthy_gcontext_commit_prediction (AnthyGContext *obj, + int nth_seg); +G_END_DECLS +#endif diff --git a/gir/test.c b/gir/test.c new file mode 100644 index 0000000..c7b9d60 --- /dev/null +++ b/gir/test.c @@ -0,0 +1,34 @@ +#include <stdio.h> + +#include "anthygcontext.h" + +int +main (int argc, char *argv[]) +{ + AnthyGContext *obj = NULL; + gchar *string = NULL; + + g_type_init (); + + obj = anthy_gcontext_new (); + + anthy_gcontext_set_encoding (obj, ANTHY_UTF8_ENCODING); + anthy_gcontext_init_personality (obj); + anthy_gcontext_do_set_personality(obj, "ibus__ibus_symbol"); + anthy_gcontext_set_string (obj, "てすと"); + anthy_gcontext_resize_segment (obj, 0, -1); + printf ("%d\n", anthy_gcontext_get_nr_segments (obj)); + printf ("%d\n", anthy_gcontext_get_nr_candidates (obj, 0)); + string = anthy_gcontext_get_segment (obj, 0, 0); + printf ("%s\n", string ? string : "(null)"); + anthy_gcontext_commit_segment (obj, 0, 0); + anthy_gcontext_set_prediction_string (obj, "てすと"); + printf ("%d\n", anthy_gcontext_get_nr_predictions (obj)); + string = anthy_gcontext_get_prediction (obj, 0); + printf ("%s\n", string ? string : "(null)"); + anthy_gcontext_commit_prediction (obj, 0); + + g_object_unref (obj); + + return 0; +} diff --git a/gir/test.py b/gir/test.py new file mode 100644 index 0000000..3a4e701 --- /dev/null +++ b/gir/test.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from gi.repository import GObject +from gi.repository import Anthy + +anthy = Anthy.GContext() +anthy.set_encoding(Anthy.UTF8_ENCODING) +anthy.init_personality() +anthy.do_set_personality('ibus__ibus_symbol') +anthy.set_string('てすと') +anthy.resize_segment(0, -1) +print anthy.get_nr_segments() +print anthy.get_nr_candidates(0) +print anthy.get_segment(0, 0) +print anthy.commit_segment(0, 0) +anthy.set_prediction_string('てすと') +print anthy.get_nr_predictions() +print anthy.get_prediction(0) +print anthy.commit_prediction(0) |