cc4dda7cc6db4c74b9c0dc5da8866f247c95d3c7
[platform/upstream/ibus-hangul.git] / src / main.c
1 /* vim:set et sts=4: */
2
3 #include <ibus.h>
4 #include <stdlib.h>
5 #include <locale.h>
6 #include <hangul.h>
7 #include "engine.h"
8
9 #define N_(text) text
10
11 static IBusBus *bus = NULL;
12 static IBusFactory *factory = NULL;
13
14 /* options */
15 static gboolean ibus = FALSE;
16 static gboolean verbose = FALSE;
17
18 static const GOptionEntry entries[] =
19 {
20     { "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL },
21     { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL },
22     { NULL },
23 };
24
25
26 static void
27 ibus_disconnected_cb (IBusBus  *bus,
28                       gpointer  user_data)
29 {
30     g_debug ("bus disconnected");
31     ibus_quit ();
32 }
33
34
35 static void
36 start_component (void)
37 {
38     IBusComponent *component;
39
40     ibus_init ();
41
42     bus = ibus_bus_new ();
43     g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
44
45     ibus_hangul_init (bus);
46
47     component = ibus_component_new ("org.freedesktop.IBus.Hangul",
48                                     N_("Hangul input method"),
49                                     "0.1.0",
50                                     "GPL",
51                                     "Peng Huang <shawn.p.huang@gmail.com>",
52                                     "http://code.google.com/p/ibus/",
53                                     "",
54                                     "ibus-hangul");
55     ibus_component_add_engine (component,
56                                ibus_engine_desc_new ("hangul",
57                                                      N_("Hangul Input Method"),
58                                                      N_("Hangul Input Method"),
59                                                      "ko",
60                                                      "GPL",
61                                                      "Peng Huang <shawn.p.huang@gmail.com>",
62                                                      PKGDATADIR"/icon/ibus-hangul.svg",
63                                                      "us"));
64
65     factory = ibus_factory_new (ibus_bus_get_connection (bus));
66
67     ibus_factory_add_engine (factory, "hangul", IBUS_TYPE_HANGUL_ENGINE);
68
69     if (ibus) {
70         ibus_bus_request_name (bus, "org.freedesktop.IBus.Hangul", 0);
71     }
72     else {
73         ibus_bus_register_component (bus, component);
74     }
75
76     g_object_unref (component);
77
78     ibus_main ();
79
80     ibus_hangul_exit ();
81 }
82
83 int
84 main (gint argc, gchar **argv)
85 {
86     GError *error = NULL;
87     GOptionContext *context;
88
89     setlocale (LC_ALL, "");
90
91     context = g_option_context_new ("- ibus hangul engine component");
92
93     g_option_context_add_main_entries (context, entries, "ibus-hangul");
94
95     if (!g_option_context_parse (context, &argc, &argv, &error)) {
96         g_print ("Option parsing failed: %s\n", error->message);
97         exit (-1);
98     }
99
100     start_component ();
101     return 0;
102 }