1 /* vim:set et ts=4 sts=4:
3 * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
5 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include "PYPointer.h"
32 #include "PYPConfig.h"
33 #ifdef IBUS_BUILD_LIBPINYIN
34 #include "PYLibPinyin.h"
41 static Pointer<IBusFactory> factory;
44 static gboolean ibus = FALSE;
45 static gboolean verbose = FALSE;
48 show_version_and_quit (void)
50 g_print ("%s - Version %s\n", g_get_application_name (), VERSION);
54 static const GOptionEntry entries[] =
56 { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
57 (gpointer) show_version_and_quit, "Show the application's version.", NULL },
58 { "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL },
59 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL },
65 ibus_disconnected_cb (IBusBus *bus,
68 g_debug ("bus disconnected");
74 start_component (void)
76 Pointer<IBusComponent> component;
81 if (!bus.isConnected ()) {
82 g_warning ("Can not connect to ibus!");
86 if (!ibus_bus_get_config (bus)) {
87 g_warning ("IBus config component is not ready!");
91 #ifdef IBUS_BUILD_LIBPINYIN
92 LibPinyinBackEnd::init ();
95 #ifdef IBUS_BUILD_LIBPINYIN
96 LibPinyinPinyinConfig::init (bus);
97 LibPinyinBopomofoConfig::init (bus);
100 g_signal_connect ((IBusBus *)bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
102 component = ibus_component_new ("org.freedesktop.IBus.Libpinyin",
103 N_("Libpinyin input method"),
106 "Peng Wu <alexepico@gmail.com>",
107 "https://github.com/libpinyin/ibus-libpinyin",
110 #ifdef IBUS_BUILD_LIBPINYIN
111 ibus_component_add_engine (component,
112 ibus_engine_desc_new ("libpinyin-debug",
113 N_("Intelligent Pinyin (debug)"),
114 N_("Intelligent Pinyin input method (debug)"),
117 "Peng Huang <shawn.p.huang@gmail.com>\n"
118 "Peng Wu <alexepico@gmail.com>\n"
119 "BYVoid <byvoid1@gmail.com>",
120 PKGDATADIR "/icons/ibus-pinyin.svg",
122 ibus_component_add_engine (component,
123 ibus_engine_desc_new ("libbopomofo-debug",
124 N_("Intelligent Bopomofo (debug)"),
125 N_("Intelligent Bopomofo input method (debug)"),
128 "BYVoid <byvoid1@gmail.com>\n"
129 "Peng Wu <alexepico@gmail.com>\n"
130 "Peng Huang <shawn.p.huang@gmail.com>",
131 PKGDATADIR "/icons/ibus-bopomofo.svg",
135 factory = ibus_factory_new (ibus_bus_get_connection (bus));
138 #ifdef IBUS_BUILD_LIBPINYIN
139 ibus_factory_add_engine (factory, "libpinyin", IBUS_TYPE_PINYIN_ENGINE);
140 ibus_factory_add_engine (factory, "libbopomofo", IBUS_TYPE_PINYIN_ENGINE);
142 ibus_bus_request_name (bus, "org.freedesktop.IBus.Libpinyin", 0);
145 #ifdef IBUS_BUILD_LIBPINYIN
146 ibus_factory_add_engine (factory, "libpinyin-debug", IBUS_TYPE_PINYIN_ENGINE);
147 ibus_factory_add_engine (factory, "libbopomofo-debug", IBUS_TYPE_PINYIN_ENGINE);
149 ibus_bus_register_component (bus, component);
160 #ifdef IBUS_BUILD_LIBPINYIN
161 LibPinyinBackEnd::finalize ();
163 ::exit (EXIT_FAILURE);
169 #ifdef IBUS_BUILD_LIBPINYIN
170 LibPinyinBackEnd::finalize ();
175 main (gint argc, gchar **argv)
177 GError *error = NULL;
178 GOptionContext *context;
180 setlocale (LC_ALL, "");
182 context = g_option_context_new ("- ibus pinyin engine component");
184 g_option_context_add_main_entries (context, entries, "ibus-libpinyin");
186 if (!g_option_context_parse (context, &argc, &argv, &error)) {
187 g_print ("Option parsing failed: %s\n", error->message);
191 ::signal (SIGTERM, sigterm_cb);
192 ::signal (SIGINT, sigterm_cb);
193 g_atexit (atexit_cb);