Merge branch 'define-symbol' of git://github.com/ueno/ibus-hangul
[platform/upstream/ibus-hangul.git] / src / main.c
1 /* vim:set et sts=4: */
2 /* ibus-hangul - The Hangul Engine For IBus
3  * Copyright (C) 2008-2009 Peng Huang <shawn.p.huang@gmail.com>
4  * Copyright (C) 2009-2011 Choe Hwanjin <choe.hwanjin@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <ibus.h>
26 #include <stdlib.h>
27 #include <locale.h>
28 #include <hangul.h>
29
30 #include "i18n.h"
31 #include "engine.h"
32
33
34 static IBusBus *bus = NULL;
35 static IBusFactory *factory = NULL;
36
37 /* options */
38 static gboolean ibus = FALSE;
39 static gboolean verbose = FALSE;
40
41 static const GOptionEntry entries[] =
42 {
43     { "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL },
44     { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL },
45     { NULL },
46 };
47
48
49 static void
50 ibus_disconnected_cb (IBusBus  *bus,
51                       gpointer  user_data)
52 {
53     g_debug ("bus disconnected");
54     ibus_quit ();
55 }
56
57
58 static void
59 start_component (void)
60 {
61     IBusComponent *component;
62
63     ibus_init ();
64
65     bus = ibus_bus_new ();
66     g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
67
68     ibus_hangul_init (bus);
69
70     component = ibus_component_new ("org.freedesktop.IBus.Hangul",
71                                     N_("Korean input method"),
72                                     "0.1.0",
73                                     "GPL",
74                                     "Peng Huang <shawn.p.huang@gmail.com>",
75                                     "http://code.google.com/p/ibus/",
76                                     "",
77                                     "ibus-hangul");
78     ibus_component_add_engine (component,
79                                ibus_engine_desc_new ("hangul",
80                                                      N_("Korean Input Method"),
81                                                      N_("Korean Input Method"),
82                                                      "ko",
83                                                      "GPL",
84                                                      "Peng Huang <shawn.p.huang@gmail.com>",
85                                                      PKGDATADIR"/icon/ibus-hangul.svg",
86                                                      "us"));
87
88     factory = ibus_factory_new (ibus_bus_get_connection (bus));
89
90     ibus_factory_add_engine (factory, "hangul", IBUS_TYPE_HANGUL_ENGINE);
91
92     if (ibus) {
93         ibus_bus_request_name (bus, "org.freedesktop.IBus.Hangul", 0);
94     }
95     else {
96         ibus_bus_register_component (bus, component);
97     }
98
99     g_object_unref (component);
100
101     ibus_main ();
102
103     ibus_hangul_exit ();
104 }
105
106 int
107 main (gint argc, gchar **argv)
108 {
109     GError *error = NULL;
110     GOptionContext *context;
111
112     setlocale (LC_ALL, "");
113
114     bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
115     bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
116     textdomain(GETTEXT_PACKAGE);
117
118     context = g_option_context_new ("- ibus hangul engine component");
119
120     g_option_context_add_main_entries (context, entries, "ibus-hangul");
121
122     if (!g_option_context_parse (context, &argc, &argv, &error)) {
123         g_print ("Option parsing failed: %s\n", error->message);
124         exit (-1);
125     }
126
127     start_component ();
128     return 0;
129 }