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.
38 #include "ibus_portable.h"
39 #include "sunpinyin_property.h"
41 #define N_(String) (String)
42 #define _(String) gettext(String)
44 static const char *PROP_STATUS = "status";
45 static const char *PROP_LETTER = "full_letter";
46 static const char *PROP_PUNCT = "full_punct";
48 PropertyInfo::PropertyInfo()
49 : label(NULL), tooltip(NULL)
52 PropertyInfo::~PropertyInfo()
57 SunPinyinProperty::create_status_prop(ibus::Engine engine, bool state)
59 SunPinyinProperty prop(engine, PROP_STATUS);
60 prop.m_info[0].label = ibus_text_new_from_static_string("EN");
61 prop.m_info[0].icon = IBUS_SUNPINYIN_ICON_DIR"/eng.svg";
62 prop.m_info[0].tooltip = ibus_text_new_from_static_string(_("Switch to Chinese input mode"));
63 prop.m_info[1].label = ibus_text_new_from_static_string("CN");
64 prop.m_info[1].icon = IBUS_SUNPINYIN_ICON_DIR"/han.svg";
65 prop.m_info[1].tooltip = ibus_text_new_from_static_string(_("Switch to English input mode"));
72 SunPinyinProperty::create_letter_prop(ibus::Engine engine, bool state)
74 SunPinyinProperty prop(engine, PROP_LETTER);
75 prop.m_info[0].label = ibus_text_new_from_static_string("Aa");
76 prop.m_info[0].icon = IBUS_SUNPINYIN_ICON_DIR"/halfwidth.svg";
77 prop.m_info[0].tooltip = ibus_text_new_from_static_string(_("Switch to full-width letter input mode"));
78 prop.m_info[1].label = ibus_text_new_from_static_string("Aa");
79 prop.m_info[1].icon = IBUS_SUNPINYIN_ICON_DIR"/fullwidth.svg";
80 prop.m_info[1].tooltip = ibus_text_new_from_static_string(_("Switch to half-width letter input mode"));
86 SunPinyinProperty::create_punct_prop(ibus::Engine engine, bool state)
88 SunPinyinProperty prop(engine, PROP_PUNCT);
89 prop.m_info[0].label = ibus_text_new_from_static_string(",.");
90 prop.m_info[0].icon = IBUS_SUNPINYIN_ICON_DIR"/enpunc.svg";
91 prop.m_info[0].tooltip = ibus_text_new_from_static_string(_("Switch to Chinese punctuation"));
92 prop.m_info[1].label = ibus_text_new_from_static_string(",。");
93 prop.m_info[1].icon = IBUS_SUNPINYIN_ICON_DIR"/cnpunc.svg";
94 prop.m_info[1].tooltip = ibus_text_new_from_static_string(_("Switch to English punctuation"));
100 SunPinyinProperty::SunPinyinProperty(ibus::Engine engine, const std::string& name)
102 ibus_property_new(name.c_str(),
104 NULL, /* label */ NULL, /* icon */
105 NULL, /* tooltip */ TRUE, /* sensitive */
106 TRUE, /* visible */ PROP_STATE_UNCHECKED, /* state */
113 SunPinyinProperty::~SunPinyinProperty()
118 SunPinyinProperty::toggle(const std::string& name)
120 if (name == m_name) {
121 // called by ibus, simple toggle current state
129 SunPinyinProperty::update(bool state)
131 if (state == m_state)
134 ibus_engine_update_property(m_engine, *this);
138 SunPinyinProperty::init(bool state)
141 int which = m_state ? 1 : 0;
142 PropertyInfo& info = m_info[which];
143 ibus_property_set_label(*this, info.label);
144 ibus_property_set_icon(*this, info.icon.c_str());
145 ibus_property_set_tooltip(*this, info.tooltip);
146 ibus_property_set_visible(*this, TRUE);
147 ibus_property_set_state(*this, state ? PROP_STATE_CHECKED : PROP_STATE_UNCHECKED);
151 SunPinyinProperty::state() const
156 SetupLauncher::SetupLauncher()
158 ibus_property_new("setup",
160 NULL, /* label */ NULL, /* icon */
161 NULL, /* tooltip */ TRUE, /* sensitive */
162 TRUE, /* visible */ PROP_STATE_UNCHECKED, /* state */
166 m_info.label = ibus_text_new_from_static_string(_("Preference"));
167 m_info.tooltip = ibus_text_new_from_static_string(_("Preference"));
168 m_info.icon = IBUS_SUNPINYIN_ICON_DIR"/setup.svg";
173 SetupLauncher::launch(const std::string& name)
175 if (m_name != name) return;
177 GError *error = NULL;
178 gchar *argv[2] = { NULL, };
180 const char* libexecdir;
182 libexecdir = g_getenv("LIBEXECDIR");
183 if (libexecdir == NULL)
184 libexecdir = LIBEXECDIR;
186 path = g_build_filename(libexecdir, "ibus-setup-sunpinyin", NULL);
190 success = g_spawn_async (NULL, argv, NULL,
192 NULL, NULL, NULL, &error);
194 g_message("Unabled to launch \"%s\"", path);
200 SetupLauncher::init()
202 ibus_property_set_label (*this, m_info.label);
203 ibus_property_set_icon (*this, m_info.icon.c_str());
204 ibus_property_set_tooltip (*this, m_info.tooltip);
205 ibus_property_set_visible (*this, TRUE);