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
ibus_disconnected_cb(IBusBus * bus,gpointer user_data)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
start_component(void)59 start_component (void)
60 {
61 IBusComponent *component;
62 IBusConfig* config;
63 gboolean res;
64
65 ibus_init ();
66
67 bus = ibus_bus_new ();
68
69 res = ibus_bus_is_connected (bus);
70 if (!res) {
71 g_warning ("Unable to connect to IBus");
72 exit (2);
73 }
74
75 config = ibus_bus_get_config (bus);
76 if (config == NULL) {
77 g_warning ("Unable to connect to IBus config component");
78 exit (3);
79 }
80
81 g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
82
83 ibus_hangul_init (bus);
84
85 component = ibus_component_new ("org.freedesktop.IBus.Hangul",
86 N_("Korean input method"),
87 "0.1.0",
88 "GPL",
89 "Peng Huang <shawn.p.huang@gmail.com>",
90 "http://code.google.com/p/ibus/",
91 "",
92 "ibus-hangul");
93 ibus_component_add_engine (component,
94 ibus_engine_desc_new ("hangul",
95 N_("Korean Input Method"),
96 N_("Korean Input Method"),
97 "ko",
98 "GPL",
99 "Peng Huang <shawn.p.huang@gmail.com>",
100 PKGDATADIR"/icon/ibus-hangul.svg",
101 "us"));
102
103 factory = ibus_factory_new (ibus_bus_get_connection (bus));
104
105 ibus_factory_add_engine (factory, "hangul", IBUS_TYPE_HANGUL_ENGINE);
106
107 if (ibus) {
108 ibus_bus_request_name (bus, "org.freedesktop.IBus.Hangul", 0);
109 }
110 else {
111 ibus_bus_register_component (bus, component);
112 }
113
114 g_object_unref (component);
115
116 ibus_main ();
117
118 ibus_hangul_exit ();
119 }
120
121 int
main(gint argc,gchar ** argv)122 main (gint argc, gchar **argv)
123 {
124 GError *error = NULL;
125 GOptionContext *context;
126
127 setlocale (LC_ALL, "");
128
129 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
130 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
131 textdomain(GETTEXT_PACKAGE);
132
133 context = g_option_context_new ("- ibus hangul engine component");
134
135 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
136
137 if (!g_option_context_parse (context, &argc, &argv, &error)) {
138 g_print ("Option parsing failed: %s\n", error->message);
139 exit (-1);
140 }
141
142 if (verbose) {
143 const gchar* value = g_getenv ("G_MESSAGES_DEBUG");
144 if (value == NULL) {
145 g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
146 }
147 }
148
149 start_component ();
150
151 return 0;
152 }
153