re-implement it in c language.
authorHuang Peng <shawn.p.huang@gmail.com>
Thu, 5 Feb 2009 08:26:43 +0000 (16:26 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Thu, 5 Feb 2009 08:26:43 +0000 (16:26 +0800)
20 files changed:
Makefile.am
configure.ac
engine/.gitignore [deleted file]
engine/Makefile.am [deleted file]
engine/engine.py [deleted file]
engine/factory.py [deleted file]
engine/hangul.engine.in [deleted file]
engine/hangul.i [deleted file]
engine/ibus-engine-hangul.in [deleted file]
engine/main.py [deleted file]
engine/test.py [deleted file]
ibus-hangul.spec.in
po/POTFILES.in
po/zh_CN.po
python-config.py [deleted file]
src/Makefile.am [new file with mode: 0644]
src/engine.c [new file with mode: 0644]
src/engine.h [new file with mode: 0644]
src/hangul.xml.in [new file with mode: 0644]
src/main.c [new file with mode: 0644]

index 167b9aa..c5d8561 100644 (file)
@@ -19,7 +19,7 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 SUBDIRS = \
-       engine \
+       src \
        icons \
        m4 \
        po \
@@ -30,7 +30,6 @@ ACLOCAL_AMFLAGS = -I m4
 EXTRA_DIST = \
        autogen.sh \
        ibus-hangul.spec.in \
-       python-config.py \
        $(NULL)
 
 noinst_DIST = \
index 77bc550..5f1ad09 100644 (file)
@@ -20,9 +20,9 @@
 
 # if not 1, append datestamp to the version number.
 m4_define([ibus_released], [0])
-m4_define([ibus_major_version], [0])
+m4_define([ibus_major_version], [1])
 m4_define([ibus_minor_version], [1])
-m4_define([ibus_micro_version], [1])
+m4_define([ibus_micro_version], [0])
 m4_define(ibus_maybe_datestamp,
     m4_esyscmd([if test x]ibus_released[ != x1; then date +.%Y%m%d | tr -d '\n\r'; fi]))
 
@@ -50,38 +50,17 @@ AC_HEADER_STDC
 AM_PROG_LIBTOOL
 
 # check libhangul
+PKG_CHECK_MODULES(IBUS, [
+    ibus-1.0
+])
 PKG_CHECK_MODULES(HANGUL, [
     libhangul
 ])
 
-# check swig
-AC_PATH_PROG(SWIG, swig)
-if test x"$SWIG" == x""; then
-     AC_MSG_ERROR([can not find swig])
-fi
-AC_SUBST(SWIG)
-
 # check env
 AC_PATH_PROG(ENV, env)
 AC_SUBST(ENV)
 
-# check python
-AM_PATH_PYTHON([2.5])
-
-AC_PATH_PROG(PYTHON_CONFIG, python$PYTHON_VERSION-config)
-if test x"$PYTHON_CONFIG" == x""; then
-    AC_PATH_PROG(PYTHON_CONFIG, python-config)
-fi
-if test x"$PYTHON_CONFIG" != x""; then
-    PYTHON_CFLAGS=`$PYTHON_CONFIG --includes`
-    PYTHON_LIBS=`$PYTHON_CONFIG --libs`
-else
-    PYTHON_CFLAGS=`$PYTHON $srcdir/python-config.py --includes`
-    PYTHON_LIBS=`$PYTHON $srcdir/python-config.py --libs`
-fi
-AC_SUBST(PYTHON_CFLAGS)
-AC_SUBST(PYTHON_LIBS)
-
 # define GETTEXT_* variables
 GETTEXT_PACKAGE=ibus-hangul
 AC_SUBST(GETTEXT_PACKAGE)
@@ -95,9 +74,8 @@ AM_GNU_GETTEXT_VERSION(0.16.1)
 AC_CONFIG_FILES([ po/Makefile.in
 Makefile
 ibus-hangul.spec
-engine/Makefile
-engine/ibus-engine-hangul
-engine/hangul.engine
+src/Makefile
+src/hangul.xml
 icons/Makefile
 m4/Makefile
 ])
diff --git a/engine/.gitignore b/engine/.gitignore
deleted file mode 100644 (file)
index 89eb2ce..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-anthy.py
-anthy_wrap.c
-ibus-engine-anthy
diff --git a/engine/Makefile.am b/engine/Makefile.am
deleted file mode 100644 (file)
index babb51b..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-# vim:set noet ts=4:
-#
-# ibus-hangul - The Hangul engine for IBus
-#
-# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
-#
-# 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.
-
-engine_hangul_PYTHON = \
-       engine.py \
-       factory.py \
-       main.py \
-       $(NULL)
-engine_hanguldir = $(pkgdatadir)/engine
-
-hangul_DATA = \
-       hangul.py \
-       $(NULL)
-hangul_LTLIBRARIES = _hangul.la
-hanguldir = @pyexecdir@
-
-_hangul_la_SOURCES = \
-       $(NULL)
-
-nodist__hangul_la_SOURCES = \
-       hangul_wrap.c \
-       $(NULL)
-
-_hangul_la_CFLAGS = \
-       @HANGUL_CFLAGS@ \
-       @PYTHON_CFLAGS@ \
-       $(NULL)
-
-_hangul_la_LDFLAGS = \
-       @HANGUL_LIBS@ \
-       @PYTHON_LIBS@ \
-       -rpath $(hanguldir) \
-       -avoid-version \
-       -module \
-       $(NULL)
-
-bin_SCRIPTS = ibus-engine-hangul
-engine_DATA = hangul.engine
-enginedir = $(datadir)/ibus/engine
-
-hangul.py hangul_wrap.c: hangul.i
-       $(SWIG) -python -I/usr/include -o hangul_wrap.c $(srcdir)/hangul.i
-
-test:
-       $(ENV) \
-               DBUS_DEBUG=true \
-               IBUS_HANGUL_PKGDATADIR=$(abs_top_srcdir) \
-               PYTHONPATH=$${PYTHONPATH}:$(builddir)/.libs \
-               $(PYTHON) \
-               $(srcdir)/main.py
-
-EXTRA_DIST = \
-       hangul.i \
-       hangul.engine.in \
-       ibus-engine-hangul.in \
-       $(NULL)
-
-CLEANFILES = \
-       hangul.py \
-       hangul_wrap.* \
-       *.pyc \
-       $(MULL)
-
-DISTCLEANFILES = \
-       $(MULL)
diff --git a/engine/engine.py b/engine/engine.py
deleted file mode 100644 (file)
index 240e565..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-# vim:set et sts=4 sw=4:
-# -*- coding: utf-8 -*-
-#
-# ibus-hangul - The Hangul engine for IBus
-#
-# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
-#
-# 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.
-
-import gobject
-import ibus
-import hangul
-from ibus import keysyms
-from ibus import modifier
-
-_ = lambda a: a
-
-class Engine(ibus.EngineBase):
-
-    # init hanja table
-    __hanja_table = None
-
-    def __init__(self, bus, object_path):
-        super(Engine, self).__init__(bus, object_path)
-        # if Engine.__hanja_table == None:
-        #     table = "/usr/share/libhangul/hanja/hanja.txt"
-        #     Engine.__hanja_table = \
-        #         hangul.HanjaTable(table)
-
-        # create anthy context
-        self.__context = hangul.HangulInputContext("2")
-        self.__reset()
-
-    # reset values of engine
-    def __reset(self):
-        self.__context.reset()
-
-    def page_up(self):
-        return True
-
-    def page_down(self):
-        return True
-
-    def cursor_up(self):
-        return True
-
-    def cursor_down(self):
-        return True
-
-    def __flush(self):
-        text = self.__context.flush()
-        self.hide_preedit()
-        self.commit_string(text)
-
-    def __update_preedit(self):
-        preedit_string = self.__context.get_preedit_string()
-        if preedit_string:
-            attrs = ibus.AttrList()
-            l = len(preedit_string)
-            attrs.append(ibus.AttributeForeground(0xffffff, 0, l))
-            attrs.append(ibus.AttributeBackground(0, 0, l))
-            self.update_preedit(preedit_string, attrs, l, True)
-        else:
-            self.hide_preedit()
-
-    def __commit_current(self):
-        commit_string = self.__context.get_commit_string()
-        if commit_string:
-            self.commit_string(commit_string)
-
-    def process_key_event(self, keyval, is_press, state):
-        # ignore key release events
-        if not is_press:
-            return False
-
-        if state & (modifier.CONTROL_MASK | modifier.MOD1_MASK):
-            return False
-
-        res = False
-        if keyval == keysyms.BackSpace:
-            res = self.__context.backspace()
-            if res:
-                self.__update_preedit()
-        else:
-            if state & modifier.LOCK_MASK:
-                # toggle case
-                c = unichr(keyval)
-                if c.islower():
-                    keyval = ord(c.upper())
-                else:
-                    keyval = ord(c.lower())
-
-            res = self.__context.process(keyval)
-            self.__update_preedit()
-            self.__commit_current()
-        return res
-
-    def property_activate(self, prop_name, state):
-        pass
-
-    def focus_in(self):
-        pass
-
-    def focus_out(self):
-        self.__flush()
diff --git a/engine/factory.py b/engine/factory.py
deleted file mode 100644 (file)
index 8181377..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-# vim:set et sts=4 sw=4:
-# -*- coding: utf-8 -*-
-#
-# ibus-hangul - The Hangul engine for IBus
-#
-# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
-#
-# 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.
-
-import os
-from os import path
-import ibus
-import engine
-
-from gettext import dgettext
-_  = lambda a : dgettext("ibus-anthy", a)
-N_ = lambda a : a
-
-FACTORY_PATH = "/com/redhat/IBus/engines/Hangul/Factory"
-ENGINE_PATH = "/com/redhat/IBus/engines/Hangul/Engine/"
-
-class EngineFactory(ibus.EngineFactoryBase):
-    NAME = _("Hangul")
-    LANG = "ko"
-    ICON = path.join(os.getenv("IBUS_HANGUL_PKGDATADIR"), "icons/ibus-hangul.png")
-    AUTHORS = "Huang Peng <shawn.p.huang@gmail.com>"
-    CREDITS = "GPLv2"
-
-    def __init__(self, bus):
-        self.__info = [
-            self.NAME,
-            self.LANG,
-            self.ICON,
-            self.AUTHORS,
-            self.CREDITS
-            ]
-
-        super(EngineFactory, self).__init__(self.__info, engine.Engine, ENGINE_PATH, bus, FACTORY_PATH)
-
-
diff --git a/engine/hangul.engine.in b/engine/hangul.engine.in
deleted file mode 100644 (file)
index 475bfa7..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-Exec=@prefix@/bin/ibus-engine-hangul
-Name=Hangul
-Lang=ko
-Icon=@prefix@/share/@PACKAGE@/icons/ibus-hangul.png
-Author=Huang Peng <shawn.p.huang@gmail.com>
-Credits=
diff --git a/engine/hangul.i b/engine/hangul.i
deleted file mode 100644 (file)
index f852a5a..0000000
+++ /dev/null
@@ -1,280 +0,0 @@
-/* vim:set et ts=4: */
-/*
- * ibus-hangul - The Hangul engine for IBus
- *
- * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
- *
- * 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.
- */
-
-%module hangul
-%{
- /* Put header files here or function declarations like below */
-#include <wchar.h>
-#include <hangul.h>
-%}
-
-%init %{
-%}
-
-%typemap (in) ucschar * {
-    if (PyUnicode_Check ($input)) {
-        Py_ssize_t size = PyUnicode_GetSize ($input);
-        $1 = (ucschar *)malloc ((size + 1) * sizeof (ucschar));
-        PyUnicode_AsWideChar ((PyUnicodeObject *)$input, (wchar_t *)$1, size);
-        $1[size] = 0;
-    }
-    else {
-        PyErr_SetString (PyExc_TypeError,
-            "arg msut be unistr");
-        return NULL;
-    }
-}
-
-%typemap(freearg) ucschar * {
-    free ($1);
-}
-
-%typemap (out) ucschar * {
-    if ($1 != NULL) {
-        $result = PyUnicode_FromWideChar ((const wchar_t *)$1,
-                    wcslen ((const wchar_t *)$1));
-    }
-    else {
-        Py_INCREF (Py_None);
-        $result = Py_None;
-    }
-}
-
-/* define exception */
-%exception {
-    $action
-    if (PyErr_Occurred ()) {
-        return NULL;
-    }
-}
-
-typedef int ucschar;
-
-/* define struct HangulKeyboard */
-typedef struct {} HangulKeyboard;
-%extend HangulKeyboard {
-    HangulKeyboard () {
-        return hangul_keyboard_new ();
-    }
-
-    ~HangulKeyboard () {
-        hangul_keyboard_delete (self);
-    }
-
-    void set_value (int key, ucschar value) {
-        hangul_keyboard_set_value (self, key, value);
-    }
-
-    void set_type (int type) {
-        hangul_keyboard_set_type (self, type);
-    }
-};
-
-/* define struct HangulCombination */
-typedef struct {} HangulCombination;
-%extend HangulCombination {
-    HangulCombination () {
-        return hangul_combination_new ();
-    }
-
-    ~HangulCombination () {
-        hangul_combination_delete (self);
-    }
-
-    bool set_data (ucschar *first, ucschar *second, ucschar *result, int n) {
-        return hangul_combination_set_data (self, first, second, result, n);
-    }
-};
-
-/* define struct HangulInputContext */
-typedef struct {} HangulInputContext;
-%extend HangulInputContext {
-    HangulInputContext (char *keyboard) {
-        return hangul_ic_new (keyboard);
-    }
-
-    ~HangulInputContext() {
-        hangul_ic_delete (self);
-    }
-
-    bool process (int ascii) {
-        return hangul_ic_process (self, ascii);
-    }
-
-    void reset () {
-        hangul_ic_reset (self);
-    }
-
-    bool backspace () {
-        return hangul_ic_backspace (self);
-    }
-
-    bool is_empty () {
-        return hangul_ic_is_empty (self);
-    }
-
-    bool has_choseong () {
-        return hangul_ic_has_choseong (self);
-    }
-
-    bool has_jungseong () {
-        return hangul_ic_has_jungseong (self);
-    }
-
-    bool has_jongseong () {
-        return hangul_ic_has_jongseong (self);
-    }
-
-    int dvorak_to_qwerty (int qwerty) {
-        return hangul_ic_dvorak_to_qwerty (qwerty);
-    }
-
-    void set_output_mode (int mode) {
-        hangul_ic_set_output_mode (self, mode);
-    }
-
-    void set_keyboard (const HangulKeyboard *keyboard) {
-        hangul_ic_set_keyboard (self, keyboard);
-    }
-
-    void select_keyboard (const char *id) {
-        hangul_ic_select_keyboard (self, id);
-    }
-
-    void set_combination (const HangulCombination *combination) {
-        hangul_ic_set_combination (self, combination);
-    }
-
-    void connect_callback (void *event, void *callback, void *user_data) {
-        hangul_ic_connect_callback (self, event, callback, user_data);
-    }
-
-    const ucschar *get_preedit_string () {
-        return hangul_ic_get_preedit_string (self);
-    }
-
-    const ucschar *get_commit_string () {
-        return hangul_ic_get_commit_string (self);
-    }
-
-    const ucschar *flush () {
-        return hangul_ic_flush (self);
-    }
-};
-
-/*
- Translate HanjaList to (key, [(v1, c1), (v2, c2), ...])
- */
-%typemap (out) HanjaList * {
-    if ($1 != NULL) {
-        int size = hanja_list_get_size ($1);
-        PyObject *key = PyString_FromString (hanja_list_get_key ($1));
-        PyObject *list = PyList_New (size);
-        int i;
-        for (i = 0; i < size; i++) {
-            const Hanja *hanja = hanja_list_get_nth ($1, i);
-            PyObject *value = PyString_FromString (hanja_get_value (hanja));
-            PyObject *comment = PyString_FromString (hanja_get_comment (hanja));
-            PyList_SetItem (list, i, PyTuple_Pack (2, value, comment));
-        }
-        hanja_list_delete ($1);
-        $result = PyTuple_Pack (2, key, list);
-    }
-    else {
-        Py_INCREF (Py_None);
-        $result = Py_None;
-    }
-}
-
-/* define HanjaTable */
-typedef struct {} HanjaTable;
-%extend HanjaTable {
-    HanjaTable (const char *name) {
-        HanjaTable *table = hanja_table_load (name);
-        if (table == NULL) {
-            PyErr_Format (PyExc_IOError,
-                            "Can not load HanjaTabel from %s.", name);
-            return NULL;
-        }
-        return table;
-    }
-
-    ~HanjaTable () {
-        hanja_table_delete (self);
-    }
-
-    HanjaList *match_prefix (const char *key) {
-        return hanja_table_match_prefix (self, key);
-    }
-
-    HanjaList *match_suffix (const char *key) {
-        return hanja_table_match_suffix (self, key);
-    }
-}
-
-bool hangul_is_choseong(ucschar c);
-bool hangul_is_jungseong(ucschar c);
-bool hangul_is_jongseong(ucschar c);
-bool hangul_is_choseong_conjoinable(ucschar c);
-bool hangul_is_jungseong_conjoinable(ucschar c);
-bool hangul_is_jongseong_conjoinable(ucschar c);
-bool hangul_is_syllable(ucschar c);
-bool hangul_is_jaso(ucschar c);
-bool hangul_is_jamo(ucschar c);
-
-/*
-ucschar hangul_jaso_to_jamo(ucschar ch);
-ucschar hangul_choseong_to_jamo(ucschar ch);
-ucschar hangul_jungseong_to_jamo(ucschar ch);
-ucschar hangul_jongseong_to_jamo(ucschar ch);
-*/
-
-ucschar hangul_choseong_to_jongseong(ucschar ch);
-ucschar hangul_jongseong_to_choseong(ucschar ch);
-
-/*
-void    hangul_jongseong_dicompose(ucschar ch, ucschar* jong, ucschar* cho);
-*/
-ucschar hangul_jaso_to_syllable(ucschar choseong,
-                ucschar jungseong,
-                ucschar jongseong);
-/*
-void    hangul_syllable_to_jaso(ucschar syllable,
-                ucschar* choseong,
-                ucschar* jungseong,
-                ucschar* jongseong);
-*/
-enum {
-    HANGUL_CHOSEONG_FILLER  = 0x115f,   /* hangul choseong filler */
-    HANGUL_JUNGSEONG_FILLER = 0x1160    /* hangul jungseong filler */
-};
-
-enum {
-    HANGUL_OUTPUT_SYLLABLE,
-    HANGUL_OUTPUT_JAMO
-};
-
-enum {
-    HANGUL_KEYBOARD_TYPE_JAMO,
-    HANGUL_KEYBOARD_TYPE_JASO
-};
-
-
diff --git a/engine/ibus-engine-hangul.in b/engine/ibus-engine-hangul.in
deleted file mode 100644 (file)
index ad4755b..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/sh
-#
-# ibus-hangul - The Hangul engine for IBus
-#
-# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this program; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
-# Boston, MA  02111-1307  USA
-prefix=@prefix@
-datarootdir=@datarootdir@
-export IBUS_PREFIX=@prefix@
-export IBUS_HANGUL_PKGDATADIR=@datarootdir@/@PACKAGE@
-exec python @datarootdir@/@PACKAGE@/engine/main.py $@
-
diff --git a/engine/main.py b/engine/main.py
deleted file mode 100644 (file)
index a6190d9..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-# vim:set et sts=4 sw=4:
-# -*- coding: utf-8 -*-
-#
-# ibus-anthy - The Anthy engine for IBus
-#
-# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
-#
-# 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.
-
-import os
-import sys
-import getopt
-import ibus
-import factory
-import gobject
-
-class IMApp:
-    def __init__(self):
-        self.__mainloop = gobject.MainLoop()
-        self.__bus = ibus.Bus()
-        self.__bus.connect("destroy", self.__bus_destroy_cb)
-        self.__engine = factory.EngineFactory(self.__bus)
-        self.__bus.register_factories([factory.FACTORY_PATH])
-
-    def run(self):
-        self.__mainloop.run()
-
-    def __bus_destroy_cb(self, bus):
-        self.__mainloop.quit()
-
-
-def launch_engine():
-    IMApp().run()
-
-def print_help(out, v = 0):
-    print >> out, "-h, --help             show this message."
-    print >> out, "-d, --daemonize        daemonize ibus"
-    sys.exit(v)
-
-def main():
-    daemonize = False
-    shortopt = "hd"
-    longopt = ["help", "daemonize"]
-    try:
-        opts, args = getopt.getopt(sys.argv[1:], shortopt, longopt)
-    except getopt.GetoptError, err:
-        print_help(sys.stderr, 1)
-
-    for o, a in opts:
-        if o in ("-h", "--help"):
-            print_help(sys.stdout)
-        elif o in ("-d", "--daemonize"):
-            daemonize = True
-        else:
-            print >> sys.stderr, "Unknown argument: %s" % o
-            print_help(sys.stderr, 1)
-
-    if daemonize:
-        if os.fork():
-            sys.exit()
-
-    launch_engine()
-
-if __name__ == "__main__":
-    main()
diff --git a/engine/test.py b/engine/test.py
deleted file mode 100755 (executable)
index 1419b9d..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-import hangul
-import sys
-sys.path.append(".libs")
-
-ctx = hangul.HangulInputContext("2")
-ctx.process(ord('a'))
-ctx.process(ord('b'))
-ctx.process(ord('c'))
-print ctx.get_preedit_string()
-print ctx.get_commit_string()
-print ctx.flush()
-print ctx.get_preedit_string()
-print ctx.get_commit_string()
-print ctx.flush()
-ctx = None
-
-table = hangul.HanjaTable("/usr/share/libhangul/hanja/hanja.txt")
-v = table.match_prefix("가례")
-if v:
-       k, l = v
-       print k
-       for v, c in l:
-               print v, c
index e17daf5..a83e0cb 100644 (file)
@@ -13,9 +13,7 @@ BuildRoot:  %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 BuildRequires:  gettext-devel
 BuildRequires:  libtool
-BuildRequires:  python-devel
 BuildRequires:  libhangul-devel
-BuildRequires:  swig
 BuildRequires:  pkgconfig
 
 Requires:   ibus
@@ -45,13 +43,9 @@ rm -rf $RPM_BUILD_ROOT
 %files -f %{name}.lang
 %defattr(-,root,root,-)
 %doc AUTHORS COPYING README
-# %dir %{python_sitearch}/ibus
-%{python_sitearch}/hangul.py*
-%{python_sitearch}/_hangul.so
-%dir %{_datadir}/@PACKAGE@
-%{_bindir}/ibus-engine-hangul
-%{_datadir}/@PACKAGE@/*
-%{_datadir}/ibus/engine/hangul.engine
+%{_libexecdir}/ibus-engine-hangul
+%{_datadir}/@PACKAGE@
+%{_datadir}/ibus/component/*
 
 %changelog
 * Fri Aug 08 2008 Huang Peng <shawn.p.huang@gmail.com> - @VERSION@-1
index 2cab87c..e723152 100644 (file)
@@ -1,3 +1 @@
-./engine/main.py
-./engine/engine.py
-./engine/factory.py
+src/main.c
index 019eeaa..e24b38f 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: http://code.google.com/p/ibus/issues/entry\n"
-"POT-Creation-Date: 2008-09-01 08:27+0800\n"
+"POT-Creation-Date: 2009-02-05 16:24+0800\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -16,6 +16,10 @@ msgstr ""
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-#: engine/factory.py:35
-msgid "Hangul"
+#: src/main.c:46
+msgid "Hangul input method"
+msgstr ""
+
+#: src/main.c:55 src/main.c:56
+msgid "Hangul Input Method"
 msgstr ""
diff --git a/python-config.py b/python-config.py
deleted file mode 100755 (executable)
index e53fb2c..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/bin/python2.5
-
-import sys
-import os
-import getopt
-from distutils import sysconfig
-
-valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags', 
-              'ldflags', 'help']
-
-def exit_with_usage(code=1):
-    print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0], 
-                                            '|'.join('--'+opt for opt in valid_opts))
-    sys.exit(code)
-
-try:
-    opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
-except getopt.error:
-    exit_with_usage()
-
-if not opts:
-    exit_with_usage()
-
-opt = opts[0][0]
-
-pyver = sysconfig.get_config_var('VERSION')
-getvar = sysconfig.get_config_var
-
-if opt == '--help':
-    exit_with_usage(0)
-
-elif opt == '--prefix':
-    print sysconfig.PREFIX
-
-elif opt == '--exec-prefix':
-    print sysconfig.EXEC_PREFIX
-
-elif opt in ('--includes', '--cflags'):
-    flags = ['-I' + sysconfig.get_python_inc(),
-             '-I' + sysconfig.get_python_inc(plat_specific=True)]
-    if opt == '--cflags':
-        flags.extend(getvar('CFLAGS').split())
-    print ' '.join(flags)
-
-elif opt in ('--libs', '--ldflags'):
-    libs = getvar('LIBS').split() + getvar('SYSLIBS').split()
-    libs.append('-lpython'+pyver)
-    # add the prefix/lib/pythonX.Y/config dir, but only if there is no
-    # shared library in prefix/lib/.
-    if opt == '--ldflags' and not getvar('Py_ENABLE_SHARED'):
-        libs.insert(0, '-L' + getvar('LIBPL'))
-    print ' '.join(libs)
-
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644 (file)
index 0000000..0ab6ca9
--- /dev/null
@@ -0,0 +1,65 @@
+# vim:set noet ts=4:
+#
+# ibus-anthy - The Anthy engine for IBus
+#
+# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+#
+# 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.
+
+AM_CFLAGS = \
+       @IBUS_CFLAGS@ \
+       @HANGUL_CFLAGS@ \
+       -DPKGDATADIR=\"$(pkgdatadir)\" \
+       $(NULL)
+AM_LDFLAGS = \
+       @IBUS_LIBS@ \
+       @HANGUL_LIBS@ \
+       $(NULL)
+
+check_PROGRAMS = \
+       $(NULL)
+
+TESTS = \
+       $(check_PROGRAMS) \
+       $(NULL)
+
+libexec_PROGRAMS = ibus-engine-hangul
+
+ibus_engine_hangul_SOURCES = \
+       main.c \
+       engine.c \
+       engine.h \
+       $(NULL)
+ibus_engine_hangul_CFLAGS = \
+       @IBUS_CFLAGS@ \
+       @HANGUL_CFLAGS@ \
+       -DPKGDATADIR=\"$(pkgdatadir)\" \
+       $(NULL)
+ibus_engine_hangul_LDFLAGS = \
+       @IBUS_LIBS@ \
+       @HANGUL_LIBS@ \
+       $(NULL)
+
+component_DATA = \
+       hangul.xml \
+       $(NULL)
+componentdir = @datadir@/ibus/component
+
+EXTRA_DIST = \
+       hangul.xml.in \
+       $(NULL)
+
+test: ibus-engine-hangul
+       $(builddir)/ibus-engine-hangul
diff --git a/src/engine.c b/src/engine.c
new file mode 100644 (file)
index 0000000..f0390c9
--- /dev/null
@@ -0,0 +1,365 @@
+/* vim:set et sts=4: */
+
+#include <ibus.h>
+#include <hangul.h>
+#include <string.h>
+#include "engine.h"
+
+typedef struct _IBusHangulEngine IBusHangulEngine;
+typedef struct _IBusHangulEngineClass IBusHangulEngineClass;
+
+struct _IBusHangulEngine {
+       IBusEngine parent;
+
+    /* members */
+    HangulInputContext *context;
+    gboolean hangul_mode;
+
+    IBusLookupTable *table;
+    IBusProperty    *hangul_mode_prop;
+    IBusPropList    *prop_list;
+};
+
+struct _IBusHangulEngineClass {
+       IBusEngineClass parent;
+};
+
+/* functions prototype */
+static void    ibus_hangul_engine_class_init   (IBusHangulEngineClass  *klass);
+static void    ibus_hangul_engine_init             (IBusHangulEngine           *hangul);
+static GObject*
+            ibus_hangul_engine_constructor  (GType                   type,
+                                             guint                   n_construct_params,
+                                             GObjectConstructParam  *construct_params);
+static void    ibus_hangul_engine_destroy              (IBusHangulEngine               *hangul);
+static gboolean
+                       ibus_hangul_engine_process_key_event
+                                            (IBusEngine             *engine,
+                                             guint                      keyval,
+                                             guint                      modifiers);
+static void ibus_hangul_engine_focus_in     (IBusEngine             *engine);
+static void ibus_hangul_engine_focus_out    (IBusEngine             *engine);
+static void ibus_hangul_engine_reset        (IBusEngine             *engine);
+static void ibus_hangul_engine_enable       (IBusEngine             *engine);
+static void ibus_hangul_engine_disable      (IBusEngine             *engine);
+#if 0
+static void ibus_engine_set_cursor_location (IBusEngine             *engine,
+                                             gint                    x,
+                                             gint                    y,
+                                             gint                    w,
+                                             gint                    h);
+static void ibus_hangul_engine_set_capabilities
+                                            (IBusEngine             *engine,
+                                             guint                   caps);
+#endif
+static void ibus_hangul_engine_page_up      (IBusEngine             *engine);
+static void ibus_hangul_engine_page_down    (IBusEngine             *engine);
+static void ibus_hangul_engine_cursor_up    (IBusEngine             *engine);
+static void ibus_hangul_engine_cursor_down  (IBusEngine             *engine);
+static void ibus_hangul_engine_toggle_hangul_mode
+                                            (IBusHangulEngine       *hangul);
+#if 0
+static void ibus_hangul_property_activate   (IBusEngine             *engine,
+                                             const gchar            *prop_name,
+                                             gint                    prop_state);
+static void ibus_hangul_engine_property_show
+                                                                                       (IBusEngine             *engine,
+                                             const gchar            *prop_name);
+static void ibus_hangul_engine_property_hide
+                                                                                       (IBusEngine             *engine,
+                                             const gchar            *prop_name);
+#endif
+
+static void ibus_hangul_engine_flush        (IBusHangulEngine       *hangul);
+static void ibus_hangul_engine_update_preedit_text
+                                            (IBusHangulEngine       *hangul);
+
+static IBusEngineClass *parent_class = NULL;
+
+GType
+ibus_hangul_engine_get_type (void)
+{
+       static GType type = 0;
+
+       static const GTypeInfo type_info = {
+               sizeof (IBusHangulEngineClass),
+               (GBaseInitFunc)         NULL,
+               (GBaseFinalizeFunc) NULL,
+               (GClassInitFunc)        ibus_hangul_engine_class_init,
+               NULL,
+               NULL,
+               sizeof (IBusHangulEngine),
+               0,
+               (GInstanceInitFunc)     ibus_hangul_engine_init,
+       };
+
+       if (type == 0) {
+               type = g_type_register_static (IBUS_TYPE_ENGINE,
+                                                                          "IBusHangulEngine",
+                                                                          &type_info,
+                                                                          (GTypeFlags) 0);
+       }
+
+       return type;
+}
+
+static void
+ibus_hangul_engine_class_init (IBusHangulEngineClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass);
+       IBusEngineClass *engine_class = IBUS_ENGINE_CLASS (klass);
+
+       parent_class = (IBusEngineClass *) g_type_class_peek_parent (klass);
+
+    object_class->constructor = ibus_hangul_engine_constructor;
+       ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_hangul_engine_destroy;
+
+    engine_class->process_key_event = ibus_hangul_engine_process_key_event;
+
+    engine_class->reset = ibus_hangul_engine_reset;
+    engine_class->enable = ibus_hangul_engine_enable;
+    engine_class->disable = ibus_hangul_engine_disable;
+
+    engine_class->focus_in = ibus_hangul_engine_focus_in;
+    engine_class->focus_out = ibus_hangul_engine_focus_out;
+
+    engine_class->page_up = ibus_hangul_engine_page_up;
+    engine_class->page_down = ibus_hangul_engine_page_down;
+
+    engine_class->cursor_up = ibus_hangul_engine_cursor_up;
+    engine_class->cursor_down = ibus_hangul_engine_cursor_down;
+}
+
+static void
+ibus_hangul_engine_init (IBusHangulEngine *hangul)
+{
+    hangul->context = hangul_ic_new ("2");
+    hangul->hangul_mode = TRUE;
+    hangul->hangul_mode_prop = ibus_property_new ("hangul_mode_prop",
+                                           PROP_TYPE_NORMAL,
+                                           NULL,
+                                           NULL,
+                                           NULL,
+                                           TRUE,
+                                           FALSE,
+                                           0,
+                                           NULL);
+
+    hangul->prop_list = ibus_prop_list_new ();
+    ibus_prop_list_append (hangul->prop_list,  hangul->hangul_mode_prop);
+
+    hangul->table = ibus_lookup_table_new (9, TRUE);
+}
+
+static GObject*
+ibus_hangul_engine_constructor (GType                   type,
+                              guint                   n_construct_params,
+                              GObjectConstructParam  *construct_params)
+{
+    IBusHangulEngine *hangul;
+
+    hangul = (IBusHangulEngine *) G_OBJECT_CLASS (parent_class)->constructor (type,
+                                                       n_construct_params,
+                                                       construct_params);
+
+    return (GObject *)hangul;
+}
+
+
+static void
+ibus_hangul_engine_destroy (IBusHangulEngine *hangul)
+{
+    if (hangul->prop_list) {
+        g_object_unref (hangul->prop_list);
+        hangul->prop_list = NULL;
+    }
+
+    if (hangul->hangul_mode_prop) {
+        g_object_unref (hangul->hangul_mode_prop);
+        hangul->hangul_mode_prop = NULL;
+    }
+
+    if (hangul->table) {
+        g_object_unref (hangul->table);
+        hangul->table = NULL;
+    }
+
+    if (hangul->context) {
+        hangul_ic_delete (hangul->context);
+        hangul->context = NULL;
+    }
+
+       IBUS_OBJECT_CLASS (parent_class)->destroy ((IBusObject *)hangul);
+}
+
+static void
+ibus_hangul_engine_update_preedit_text (IBusHangulEngine *hangul)
+{
+    const gunichar *str;
+    IBusText *text;
+
+    str = hangul_ic_get_preedit_string (hangul->context);
+
+    if (str != NULL && str[0] != 0) {
+        text = ibus_text_new_from_ucs4 (str);
+        ibus_text_append_attribute (text, IBUS_ATTR_TYPE_FOREGROUND, 0x00ffffff, 0, -1);
+        ibus_text_append_attribute (text, IBUS_ATTR_TYPE_BACKGROUND, 0x00000000, 0, -1);
+        ibus_engine_update_preedit_text ((IBusEngine *)hangul,
+                                         text,
+                                         ibus_text_get_length (text),
+                                         TRUE);
+        g_object_unref (text);
+    }
+    else {
+        text = ibus_text_new_from_static_string ("");
+        ibus_engine_update_preedit_text ((IBusEngine *)hangul, text, 0, FALSE);
+        g_object_unref (text);
+    }
+}
+
+static gboolean
+ibus_hangul_engine_process_key_event (IBusEngine     *engine,
+                                      guint           keyval,
+                                      guint           modifiers)
+{
+    IBusHangulEngine *hangul = (IBusHangulEngine *) engine;
+
+    gboolean retval;
+    const gunichar *str;
+
+    if (modifiers & IBUS_RELEASE_MASK)
+        return FALSE;
+
+    if (modifiers & (IBUS_CONTROL_MASK | IBUS_MOD1_MASK))
+        return FALSE;
+
+    if (keyval == IBUS_BackSpace) {
+        retval = hangul_ic_backspace (hangul->context);
+        return retval;
+    }
+
+    if (keyval >= IBUS_exclam && keyval <= IBUS_asciitilde) {
+        retval = hangul_ic_process (hangul->context, keyval);
+
+        str = hangul_ic_get_commit_string (hangul->context);
+
+        if (str != NULL && str[0] != 0) {
+            IBusText *text = ibus_text_new_from_ucs4 (str);
+            ibus_engine_commit_text ((IBusEngine *)hangul, text);
+            g_object_unref (text);
+        }
+
+        ibus_hangul_engine_update_preedit_text (hangul);
+        return retval;
+    }
+
+    ibus_hangul_engine_flush (hangul);
+    return FALSE;
+}
+
+static void
+ibus_hangul_engine_flush (IBusHangulEngine *hangul)
+{
+    const gunichar *str;
+    IBusText *text;
+
+    str = hangul_ic_flush (hangul->context);
+
+    if (str == NULL || str[0] == 0)
+        return;
+
+    text = ibus_text_new_from_ucs4 (str);
+
+    ibus_engine_hide_preedit_text ((IBusEngine *) hangul);
+    ibus_engine_commit_text ((IBusEngine *) hangul, text);
+
+    g_object_unref (text);
+}
+
+static void
+ibus_hangul_engine_toggle_hangul_mode (IBusHangulEngine *hangul)
+{
+    IBusText *text;
+    hangul->hangul_mode = ! hangul->hangul_mode;
+
+    ibus_hangul_engine_flush (hangul);
+
+    if (hangul->hangul_mode) {
+        text = ibus_text_new_from_static_string ("한");
+    }
+    else {
+        text = ibus_text_new_from_static_string ("A");
+    }
+
+    ibus_property_set_label (hangul->hangul_mode_prop, text);
+    ibus_engine_update_property ((IBusEngine *)hangul, hangul->hangul_mode_prop);
+    g_object_unref (text);
+}
+
+static void
+ibus_hangul_engine_focus_in (IBusEngine *engine)
+{
+    IBusHangulEngine *hangul = (IBusHangulEngine *) engine;
+
+    ibus_engine_register_properties (engine, hangul->prop_list);
+
+    parent_class->focus_in (engine);
+}
+
+static void
+ibus_hangul_engine_focus_out (IBusEngine *engine)
+{
+    IBusHangulEngine *hangul = (IBusHangulEngine *) engine;
+
+    ibus_hangul_engine_flush (hangul);
+
+    parent_class->focus_out ((IBusEngine *) hangul);
+}
+
+static void
+ibus_hangul_engine_reset (IBusEngine *engine)
+{
+    IBusHangulEngine *hangul = (IBusHangulEngine *) engine;
+
+    ibus_hangul_engine_flush (hangul);
+    parent_class->reset (engine);
+}
+
+static void
+ibus_hangul_engine_enable (IBusEngine *engine)
+{
+    parent_class->enable (engine);
+}
+
+static void
+ibus_hangul_engine_disable (IBusEngine *engine)
+{
+    ibus_hangul_engine_focus_out (engine);
+    parent_class->disable (engine);
+}
+
+static void
+ibus_hangul_engine_page_up (IBusEngine *engine)
+{
+    parent_class->page_up (engine);
+}
+
+static void
+ibus_hangul_engine_page_down (IBusEngine *engine)
+{
+    parent_class->page_down (engine);
+}
+
+static void
+ibus_hangul_engine_cursor_up (IBusEngine *engine)
+{
+    parent_class->cursor_up (engine);
+}
+
+static void
+ibus_hangul_engine_cursor_down (IBusEngine *engine)
+{
+    parent_class->cursor_down (engine);
+}
+
diff --git a/src/engine.h b/src/engine.h
new file mode 100644 (file)
index 0000000..8ecfeb9
--- /dev/null
@@ -0,0 +1,12 @@
+/* vim:set et sts=4: */
+#ifndef __ENGINE_H__
+#define __ENGINE_H__
+
+#include <ibus.h>
+
+#define IBUS_TYPE_HANGUL_ENGINE        \
+       (ibus_hangul_engine_get_type ())
+
+GType   ibus_hangul_engine_get_type    (void);
+
+#endif
diff --git a/src/hangul.xml.in b/src/hangul.xml.in
new file mode 100644 (file)
index 0000000..445a260
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- filename: hangul.xml -->
+<component>
+       <name>org.freedesktop.IBus.Hangul</name>
+       <description>Hangul Component</description>
+       <exec>@prefix@/libexec/ibus-engine-hangul --ibus</exec>
+       <version>@VERSION@</version>
+       <author>Peng Huang &lt;shawn.p.huang@gmail.com&gt;</author>
+       <license>GPL</license>
+       <homepage>http://code.google.com/p/ibus</homepage>
+       <textdomain>ibus-hanful</textdomain>
+
+       <engines>
+               <engine>
+                       <name>hangul</name>
+                       <language>ko</language>
+                       <license>GPL</license>
+                       <author>Peng Huang &lt;shawn.p.huang@gmail.com&gt;</author>
+                       <icon>@prefix@/share/ibus-hangul/icons/ibus-hangul.png</icon>
+                       <layout>us</layout>
+                       <longname>Hangul</longname>
+                       <description>Hangul Input Method</description>
+               </engine>
+       </engines>
+
+</component>
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..654a458
--- /dev/null
@@ -0,0 +1,98 @@
+/* vim:set et sts=4: */
+
+#include <ibus.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <hangul.h>
+#include "engine.h"
+
+#define N_(text) text
+
+static IBusBus *bus = NULL;
+static IBusFactory *factory = NULL;
+
+/* options */
+static gboolean ibus = FALSE;
+static gboolean verbose = FALSE;
+
+static const GOptionEntry entries[] =
+{
+    { "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL },
+    { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL },
+    { NULL },
+};
+
+
+static void
+ibus_disconnected_cb (IBusBus  *bus,
+                      gpointer  user_data)
+{
+    g_debug ("bus disconnected");
+    ibus_quit ();
+}
+
+
+static void
+start_component (void)
+{
+    IBusComponent *component;
+
+    ibus_init ();
+
+    bus = ibus_bus_new ();
+    g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
+
+    component = ibus_component_new ("org.freedesktop.IBus.Hangul",
+                                    N_("Hangul input method"),
+                                    "0.1.0",
+                                    "GPL",
+                                    "Peng Huang <shawn.p.huang@gmail.com>",
+                                    "http://code.google.com/p/ibus/",
+                                    "",
+                                    "ibus-hangul");
+    ibus_component_add_engine (component,
+                               ibus_engine_desc_new ("hangul",
+                                                     N_("Hangul Input Method"),
+                                                     N_("Hangul Input Method"),
+                                                     "ko",
+                                                     "GPL",
+                                                     "Peng Huang <shawn.p.huang@gmail.com>",
+                                                     PKGDATADIR"/icon/ibus-hangul.svg",
+                                                     "us"));
+
+    factory = ibus_factory_new (ibus_bus_get_connection (bus));
+
+    ibus_factory_add_engine (factory, "hangul", IBUS_TYPE_HANGUL_ENGINE);
+
+    if (ibus) {
+        ibus_bus_request_name (bus, "org.freedesktop.IBus.Hangul", 0);
+    }
+    else {
+        ibus_bus_register_component (bus, component);
+    }
+
+    g_object_unref (component);
+
+    ibus_main ();
+}
+
+int
+main (gint argc, gchar **argv)
+{
+    GError *error = NULL;
+    GOptionContext *context;
+
+    setlocale (LC_ALL, "");
+
+    context = g_option_context_new ("- ibus hangul engine component");
+
+    g_option_context_add_main_entries (context, entries, "ibus-hangul");
+
+    if (!g_option_context_parse (context, &argc, &argv, &error)) {
+        g_print ("Option parsing failed: %s\n", error->message);
+        exit (-1);
+    }
+
+    start_component ();
+    return 0;
+}