2 * Copyright (c) 2009 Kov Chai <tchaikov@gmail.com>
4 * The contents of this file are subject to the terms of either the GNU Lesser
5 * General Public License Version 2.1 only ("LGPL") or the Common Development and
6 * Distribution License ("CDDL")(collectively, the "License"). You may not use this
7 * file except in compliance with the License. You can obtain a copy of the CDDL at
8 * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at
9 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the
10 * specific language governing permissions and limitations under the License. When
11 * distributing the software, include this License Header Notice in each file and
12 * include the full text of the License in the License file as well as the
15 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
17 * For Covered Software in this distribution, this License shall be governed by the
18 * laws of the State of California (excluding conflict-of-law provisions).
19 * Any litigation relating to this License shall be subject to the jurisdiction of
20 * the Federal Courts of the Northern District of California and the state courts
21 * of the State of California, with venue lying in Santa Clara County, California.
25 * If you wish your version of this file to be governed by only the CDDL or only
26 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
27 * include this software in this distribution under the [CDDL or LGPL Version 2.1]
28 * license." If you don't indicate a single choice of license, a recipient has the
29 * option to distribute your version of this file under either the CDDL or the LGPL
30 * Version 2.1, or to extend the choice of license to its licensees as provided
31 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
32 * Version 2 license, then the option applies only if the new code is made subject
33 * to such option by the copyright holder.
43 #include "ibus_common.h"
44 #include "sunpinyin_config.h"
46 #define N_(String) (String)
47 #define _(String) gettext(String)
49 static ibus::Factory factory;
52 static gboolean by_ibus = FALSE;
53 static gboolean verbose = FALSE;
55 static const GOptionEntry entries[] =
57 { "ibus", 'i', 0, G_OPTION_ARG_NONE, &by_ibus, "component is executed by ibus", NULL },
58 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL },
64 ibus_disconnected_cb (IBusBus *bus,
71 ibus::Component component;
77 bus = ibus_bus_new ();
78 g_object_ref_sink(bus);
80 if (!ibus_bus_is_connected (bus)) {
81 g_warning("Can not connect to ibus");
85 g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
87 IBusConfig* config = ibus_bus_get_config(bus);
88 g_object_ref_sink(config);
90 SunPinyinConfig::set_config(config);
93 component = ibus_component_new ("org.freedesktop.IBus.SunPinyin",
97 "Kov Chai <tchaikov@gmail.com>",
98 "http://code.google.com/p/sunpinyin/",
101 ibus_component_add_engine (component,
102 ibus_engine_desc_new ("sunpinyin",
104 _("Simplified Chinese Input Method developed by SUN"),
107 "Kov Chai <tchaikov@gmail.com>",
108 IBUS_SUNPINYIN_ICON_DIR"/sunpinyin-logo.png",
111 factory = ibus_factory_new (ibus_bus_get_connection (bus));
112 ibus_factory_add_engine (factory, "sunpinyin", IBUS_TYPE_SUNPINYIN_ENGINE);
115 ibus_bus_request_name (bus, "org.freedesktop.IBus.SunPinyin", 0);
117 ibus_bus_register_component (bus, component);
122 int main(int argc, char *argv[])
125 setlocale (LC_ALL, "");
126 bindtextdomain (GETTEXT_PACKAGE, IBUS_SUNPINYIN_LOCALEDIR);
127 textdomain (GETTEXT_PACKAGE);
129 GOptionContext* context;
130 context = g_option_context_new ("- ibus sunpinyin engine component");
131 g_option_context_add_main_entries (context, entries, "ibus-sunpinyin");
132 GError *error = NULL;
133 if (!g_option_context_parse (context, &argc, &argv, &error)) {
134 g_print ("Option parsing failed: %s\n", error->message);
137 // mask SIGTERM so that the destroy() method has the chance to be called
138 // in case user quits X session.