1 /* vim:set et ts=4 sts=4:
3 * ibus-pinyin - The Chinese PinYin engine 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., 675 Mass Ave, Cambridge, MA 02139, 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 ();
94 PinyinConfig::init (bus);
95 BopomofoConfig::init (bus);
96 #ifdef IBUS_BUILD_LIBPINYIN
97 LibPinyinPinyinConfig::init (bus);
98 LibPinyinBopomofoConfig::init (bus);
101 g_signal_connect ((IBusBus *)bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
103 component = ibus_component_new ("org.freedesktop.IBus.Pinyin",
104 N_("Pinyin input method"),
107 "Peng Huang <shawn.p.huang@gmail.com>",
108 "http://code.google.com/p/ibus/",
111 #ifdef IBUS_BUILD_LIBPINYIN
112 ibus_component_add_engine (component,
113 ibus_engine_desc_new ("libpinyin-debug",
114 N_("Intelligent Pinyin (debug)"),
115 N_("Intelligent Pinyin input method (debug)"),
118 "Peng Huang <shawn.p.huang@gmail.com>\n"
119 "Peng Wu <alexepico@gmail.com>\n"
120 "BYVoid <byvoid1@gmail.com>",
121 PKGDATADIR "/icons/ibus-pinyin.svg",
123 ibus_component_add_engine (component,
124 ibus_engine_desc_new ("libbopomofo-debug",
125 N_("Intelligent Bopomofo (debug)"),
126 N_("Intelligent Bopomofo input method (debug)"),
129 "BYVoid <byvoid1@gmail.com>\n"
130 "Peng Wu <alexepico@gmail.com>\n"
131 "Peng Huang <shawn.p.huang@gmail.com>",
132 PKGDATADIR "/icons/ibus-bopomofo.svg",
136 factory = ibus_factory_new (ibus_bus_get_connection (bus));
139 #ifdef IBUS_BUILD_LIBPINYIN
140 ibus_factory_add_engine (factory, "libpinyin", IBUS_TYPE_PINYIN_ENGINE);
141 ibus_factory_add_engine (factory, "libbopomofo", IBUS_TYPE_PINYIN_ENGINE);
143 ibus_bus_request_name (bus, "org.freedesktop.IBus.Pinyin", 0);
146 #ifdef IBUS_BUILD_LIBPINYIN
147 ibus_factory_add_engine (factory, "libpinyin-debug", IBUS_TYPE_PINYIN_ENGINE);
148 ibus_factory_add_engine (factory, "libbopomofo-debug", IBUS_TYPE_PINYIN_ENGINE);
150 ibus_bus_register_component (bus, component);
161 #ifdef IBUS_BUILD_LIBPINYIN
162 LibPinyinBackEnd::finalize ();
164 ::exit (EXIT_FAILURE);
170 #ifdef IBUS_BUILD_LIBPINYIN
171 LibPinyinBackEnd::finalize ();
176 main (gint argc, gchar **argv)
178 GError *error = NULL;
179 GOptionContext *context;
181 setlocale (LC_ALL, "");
183 context = g_option_context_new ("- ibus pinyin engine component");
185 g_option_context_add_main_entries (context, entries, "ibus-pinyin");
187 if (!g_option_context_parse (context, &argc, &argv, &error)) {
188 g_print ("Option parsing failed: %s\n", error->message);
192 ::signal (SIGTERM, sigterm_cb);
193 ::signal (SIGINT, sigterm_cb);
194 g_atexit (atexit_cb);