Codebase list mozc / upstream/2.26.4220.100
Enable to modify the iBus keyboard layout without the root permission. Update from the upstream. (BUILD=4220) * Enabled to dynamically generate the entries of iBus engines. * Enabled to modify the iBus keyboard layout without the root permission. ----- After this change, the contents of /usr/share/ibus/component/mozc.xml is changed as follows. Before ``` <component> <name>com.google.IBus.Mozc</name> <description>Mozc Component</description> <exec>/usr/lib/ibus-mozc/ibus-engine-mozc --ibus</exec> <version>0.0.0.0</version> <author>Google Inc.</author> <license>New BSD</license> <homepage>https://github.com/google/mozc</homepage> <textdomain>ibus-mozc</textdomain> <engines> <engine> <description>Mozc (Japanese Input Method)</description> <language>ja</language> <icon>/usr/share/ibus-mozc/product_icon.png</icon> <rank>80</rank> <icon_prop_key>InputMode</icon_prop_key> <symbol>&#x3042;</symbol> <setup>/usr/lib/mozc/mozc_tool --mode=config_dialog</setup> <name>mozc-jp</name> <longname>Mozc</longname> <layout>default</layout> </engine> </engines> </component> ``` After ``` <component> <name>com.google.IBus.Mozc</name> <description>Mozc Component</description> <exec>/usr/lib/ibus-mozc/ibus-engine-mozc --ibus</exec> <version>0.0.0.0</version> <author>Google Inc.</author> <license>New BSD</license> <homepage>https://github.com/google/mozc</homepage> <textdomain>ibus-mozc</textdomain> <engines exec="/usr/lib/ibus-mozc/ibus-engine-mozc --xml" /> </component> <!-- Settings of <engines> and <layout> are stored in ibus_config.textproto --> <!-- under the user configuration directory, which is either of: --> <!-- * $XDG_CONFIG_HOME/mozc/ibus_config.textproto --> <!-- * $HOME/.config/mozc/ibus_config.textproto --> <!-- * $HOME/.mozc/ibus_config.textproto --> ``` Then, `/usr/lib/ibus-mozc/ibus-engine-mozc --xml` returns the values of the <engine> tags. If `ibus_config.textproto` exists under the user config directory. (i.e. `~/.mozc/ibus_config.textproto` or `~/.config/mozc/ibus_config.textproto`) Mozc uses the settings in the file. If `ibus_config.textproto` does not exist, it is created with the default values. So, the users do not need to modify `/usr/share/ibus/component/mozc.xml` directly. This is the same mechanism with ibus-anthy. This change will fix two issues. * There was no way to use Kana layout for US keyboard. With this change, if the layout is us, Kana layout for US keyboard is used instead of JP keyboard. * If multilingual layouts were selected, the keyboard layout for Mozc was not stable. For example, when US and FR keyboards were selected in addition to Mozc, Mozc's layout was not stable. This change enables to specify the static layout for Mozc. Hiroyuki Komatsu 3 years ago
11 changed file(s) with 464 addition(s) and 73 deletion(s). Raw diff Collapse all Expand all
3232 MINOR = 26
3333
3434 # Number to be increased. This value may be replaced by other tools.
35 BUILD = 4219
35 BUILD = 4220
3636
3737 # Represent the platform and release channel.
3838 REVISION = 100
3535 "py_binary_mozc",
3636 "select_mozc",
3737 )
38 load("//tools/build_defs:stubs.bzl", "portable_proto_library")
3839
3940 package(default_visibility = ["//:__subpackages__"])
4041
4950 srcs = ["gen_mozc_xml.py"],
5051 )
5152
52 # This genrule uses pkg-config in gen_mozc_xml_main.
5353 genrule(
5454 name = "gen_mozc_xml",
5555 outs = ["mozc.xml"],
56 cmd = select_mozc(
57 default = "touch $@", # This is stub.
58 linux = ("$(location :gen_mozc_xml_main) --branding=Mozc" +
59 " --server_dir=" + MOZC_SERVER_DIRECTORY +
60 " --ibus_mozc_path=" + IBUS_MOZC_PATH +
61 " --ibus_mozc_icon_path=" + IBUS_MOZC_ICON_PATH +
62 " > $@"),
63 ),
56 cmd = ("$(location :gen_mozc_xml_main) --branding=Mozc" +
57 " --server_dir=" + MOZC_SERVER_DIRECTORY +
58 " --ibus_mozc_path=" + IBUS_MOZC_PATH +
59 " --ibus_mozc_icon_path=" + IBUS_MOZC_ICON_PATH +
60 " > $@"),
6461 exec_tools = [":gen_mozc_xml_main"],
6562 )
6663
67 # This genrule uses pkg-config in gen_mozc_xml_main.
6864 genrule(
6965 name = "gen_main_h",
7066 outs = ["main.h"],
71 cmd = select_mozc(
72 default = "touch $@", # This is stub.
73 linux = ("$(location :gen_mozc_xml_main) --branding=Mozc" +
74 " --output_cpp" +
75 " --ibus_mozc_path=" + IBUS_MOZC_PATH +
76 " --ibus_mozc_icon_path=" + IBUS_MOZC_ICON_PATH +
77 " > $@"),
78 ),
67 cmd = ("$(location :gen_mozc_xml_main) --branding=Mozc" +
68 " --output_cpp" +
69 " --ibus_mozc_path=" + IBUS_MOZC_PATH +
70 " --ibus_mozc_icon_path=" + IBUS_MOZC_ICON_PATH +
71 " > $@"),
7972 exec_tools = [":gen_mozc_xml_main"],
8073 )
8174
168161 "surrounding_text_util.h",
169162 ],
170163 ),
164 defines = [
165 "ENABLE_GTK_RENDERER",
166 "MOZC_ENABLE_X11_SELECTION_MONITOR",
167 ],
171168 deps = [
172169 ":gtk_candidate_window_handler",
170 ":ibus_config",
173171 ":ibus_property_handler",
174172 ":ibus_utils",
175173 ":x11_selection_monitor",
179177 ],
180178 )
181179
180 proto_library(
181 name = "ibus_config_proto_full",
182 srcs = [
183 "ibus_config.proto",
184 ],
185 )
186
187 portable_proto_library(
188 name = "ibus_config_proto",
189 config_string = "allow_all: true",
190 header_outs = [
191 "ibus_config.pb.h",
192 ],
193 proto_deps = ["ibus_config_proto_full"],
194 )
195
196 cc_library_mozc(
197 name = "ibus_config",
198 srcs = ["ibus_config.cc"],
199 hdrs = [
200 "ibus_config.h",
201 ":gen_main_h",
202 ],
203 copts = ["-Wno-unused-variable"],
204 deps = [
205 ":ibus_config_proto",
206 "//base:file_stream",
207 "//base:file_util",
208 "//base:logging",
209 "//base:system_util",
210 "//base/protobuf:text_format",
211 "@com_google_absl//absl/strings",
212 ],
213 )
214
182215 cc_binary_mozc(
183216 name = "ibus_mozc",
184217 srcs = select_mozc(
190223 ),
191224 data = [":gen_mozc_xml"],
192225 deps = [
226 ":ibus_config",
193227 ":ibus_mozc_lib",
194228 ":ibus_mozc_metadata",
195229 "//base",
230 "//base:flags",
196231 "//base:init_mozc",
197232 ],
198233 )
3939
4040 import optparse
4141 import os
42 import subprocess
4342 import sys
4443
4544 # Information to generate <component> part of mozc.xml. %s will be replaced with
6766
6867 #ifndef %s
6968 #define %s
69
70 #include <cstddef>
71
7072 namespace {"""
7173
7274 CPP_FOOTER = """} // namespace
7375 #endif // %s"""
7476
7577
76 def OutputXmlElement(param_dict, element_name, value):
77 print(' <%s>%s</%s>' % (element_name, (value % param_dict), element_name))
78 def GetXmlElement(param_dict, element_name, value):
79 return ' <%s>%s</%s>' % (element_name, (value % param_dict), element_name)
80
81
82 def GetTextProtoElement(param_dict, element_name, value):
83 return ' %s : "%s"' % (element_name, (value % param_dict))
84
85
86 def GetEnginesXml(param_dict, engine_common, engines, setup_arg):
87 """Outputs a XML data for ibus-daemon.
88
89 Args:
90 param_dict: A dictionary to embed options into output string.
91 For example, {'product_name': 'Mozc'}.
92 engine_common: A dictionary from a property name to a property value that
93 are commonly used in all engines. For example, {'language': 'ja'}.
94 engines: A dictionary from a property name to a list of property values of
95 engines. For example, {'name': ['mozc-jp', 'mozc', 'mozc-dv']}.
96 setup_arg: A command line to execute Mozc's configuration tool.
97 Returns:
98 output string in XML.
99 """
100 output = ['<engines>']
101 for i in range(len(engines['name'])):
102 output.append('<engine>')
103 for key in engine_common:
104 output.append(GetXmlElement(param_dict, key, engine_common[key]))
105 if setup_arg:
106 output.append(GetXmlElement(param_dict, 'setup', ' '.join(setup_arg)))
107 for key in engines:
108 output.append(GetXmlElement(param_dict, key, engines[key][i]))
109 output.append('</engine>')
110 output.append('</engines>')
111 return '\n'.join(output)
112
113
114 def GetIbusConfigTextProto(param_dict, engines):
115 """Outputs a TextProto data for iBus config.
116
117 Args:
118 param_dict: A dictionary to embed options into output string.
119 For example, {'product_name': 'Mozc'}.
120 engines: A dictionary from a property name to a list of property values of
121 engines. For example, {'name': ['mozc-jp', 'mozc', 'mozc-dv']}.
122 Returns:
123 output string in TextProto.
124 """
125 output = []
126 for i in range(len(engines['name'])):
127 output.append('engines {')
128 for key in engines:
129 output.append(GetTextProtoElement(param_dict, key, engines[key][i]))
130 output.append('}')
131 return '\n'.join(output)
78132
79133
80134 def OutputXml(param_dict, component, engine_common, engines, setup_arg):
89143 are commonly used in all engines. For example, {'language': 'ja'}.
90144 engines: A dictionary from a property name to a list of property values of
91145 engines. For example, {'name': ['mozc-jp', 'mozc', 'mozc-dv']}.
92 """
146 setup_arg: A command line to execute Mozc's configuration tool.
147 """
148 del engine_common, engines, setup_arg
93149 print('<component>')
94150 for key in component:
95 OutputXmlElement(param_dict, key, component[key])
96 print('<engines>')
97 for i in range(len(engines['name'])):
98 print('<engine>')
99 for key in engine_common:
100 OutputXmlElement(param_dict, key, engine_common[key])
101 if setup_arg:
102 OutputXmlElement(param_dict, 'setup', ' '.join(setup_arg))
103 for key in engines:
104 OutputXmlElement(param_dict, key, engines[key][i])
105 print('</engine>')
106 print('</engines>')
151 print(GetXmlElement(param_dict, key, component[key]))
152 print(' <engines exec="%s --xml" />' % param_dict['ibus_mozc_path'])
107153 print('</component>')
154
155 print('''
156 <!-- Settings of <engines> and <layout> are stored in ibus_config.textproto -->
157 <!-- under the user configuration directory, which is either of: -->
158 <!-- * $XDG_CONFIG_HOME/mozc/ibus_config.textproto -->
159 <!-- * $HOME/.config/mozc/ibus_config.textproto -->
160 <!-- * $HOME/.mozc/ibus_config.textproto -->
161 ''')
108162
109163
110164 def OutputCppVariable(param_dict, prefix, variable_name, value):
112166 (value % param_dict)))
113167
114168
115 def OutputCpp(param_dict, component, engine_common, engines):
169 def OutputCpp(param_dict, component, engine_common, engines, setup_arg):
116170 """Outputs a C++ header file for mozc/unix/ibus/main.cc.
117171
118172 Args:
120174 component: ditto.
121175 engine_common: ditto.
122176 engines: ditto.
177 setup_arg: ditto.
123178 """
124179 guard_name = 'MOZC_UNIX_IBUS_MAIN_H_'
125180 print(CPP_HEADER % (guard_name, guard_name))
127182 OutputCppVariable(param_dict, 'Component', key, component[key])
128183 for key in engine_common:
129184 OutputCppVariable(param_dict, 'Engine', key, engine_common[key])
185 OutputCppVariable(param_dict, 'Engine', 'Setup', ' '.join(setup_arg))
130186 for key in engines:
131187 print('const char* kEngine%sArray[] = {' % key.capitalize())
132188 for i in range(len(engines[key])):
133189 print('"%s",' % (engines[key][i] % param_dict))
134190 print('};')
135191 print('const size_t kEngineArrayLen = %s;' % len(engines['name']))
192 print('const char kEnginesXml[] = R"#(', end='')
193 print(GetEnginesXml(param_dict, engine_common, engines, setup_arg))
194 print(')#";')
195 print('const char kIbusConfigTextProto[] = R"#(', end='')
196 print(GetIbusConfigTextProto(param_dict, engines))
197 print(')#";')
136198 print(CPP_FOOTER % guard_name)
137
138
139 def CheckIBusVersion(options, minimum_version):
140 """Tests if ibus version is equal to or greater than the given value."""
141 command_line = ['pkg-config', '--exists', 'ibus-1.0 >= %s' % minimum_version]
142 return_code = subprocess.call(command_line)
143 if return_code == 0:
144 return True
145 else:
146 return False
147199
148200
149201 def main():
180232 'language': 'ja',
181233 'icon': '%(ibus_mozc_icon_path)s',
182234 'rank': '80',
235 # Make sure that the property key 'InputMode' matches to the property name
236 # specified to |ibus_property_new| in unix/ibus/property_handler.cc
237 'icon_prop_key': 'InputMode',
238 'symbol': '&#x3042;',
183239 }
184240
185241 # DO NOT change the engine name 'mozc-jp'. The names is referenced by
187243 engines_props = {
188244 'name': ['mozc-jp'],
189245 'longname': ['%(product_name)s'],
246 'layout': ['default'],
190247 }
191
192 # IBus 1.5.11 and greater supports 'icon_prop_key'.
193 # See ibus/ibus@23c45b970b195008a54884a1a9d810e7f8b22c5c
194 if CheckIBusVersion(options, '1.5.11'):
195 # Make sure that the property key 'InputMode' matches to the property name
196 # specified to |ibus_property_new| in unix/ibus/property_handler.cc
197 engine_common_props['icon_prop_key'] = 'InputMode'
198
199 if CheckIBusVersion(options, '1.5.0'):
200 engine_common_props['symbol'] = '&#x3042;'
201 engines_props['layout'] = ['default']
202 else:
203 engines_props['layout'] = ['jp']
204248
205249 if options.output_cpp:
206250 OutputCpp(param_dict, IBUS_COMPONENT_PROPS, engine_common_props,
207 engines_props)
251 engines_props, setup_arg)
208252 else:
209253 OutputXml(param_dict, IBUS_COMPONENT_PROPS, engine_common_props,
210254 engines_props, setup_arg)
134134 ],
135135 },
136136 {
137 'target_name': 'genproto_ibus_config_proto',
138 'type': 'none',
139 'toolsets': ['host'],
140 'sources': [
141 'ibus_config.proto',
142 ],
143 'includes': [
144 '../../protobuf/genproto.gypi',
145 ],
146 },
147 {
148 'target_name': 'ibus_config_proto',
149 'type': 'static_library',
150 'hard_dependency': 1,
151 'sources': [
152 '<(proto_out_dir)/unix/ibus/ibus_config.pb.cc',
153 ],
154 'dependencies': [
155 '../../protobuf/protobuf.gyp:protobuf',
156 'genproto_ibus_config_proto#host',
157 ],
158 'export_dependent_settings': [
159 'genproto_ibus_config_proto#host',
160 ],
161 },
162 {
137163 'target_name': 'ibus_mozc_lib',
138164 'type': 'static_library',
139165 'sources': [
140166 'engine_registrar.cc',
141167 'ibus_candidate_window_handler.cc',
168 'ibus_config.cc',
142169 'key_event_handler.cc',
143170 'key_translator.cc',
144171 'mozc_engine.cc',
146173 'surrounding_text_util.cc',
147174 ],
148175 'dependencies': [
176 '../../base/absl.gyp:absl_strings',
149177 '../../client/client.gyp:client',
150178 '../../protocol/protocol.gyp:commands_proto',
151179 '../../session/session_base.gyp:ime_switch_util',
180 'gen_ibus_mozc_files',
181 'ibus_config_proto',
152182 'ibus_property_handler',
153183 'message_translator',
154184 'path_util',
167197 ],
168198 },
169199 {
170 'target_name': 'ibus_mozc',
171 'type': 'executable',
172 'sources': [
173 'main.cc',
174 '<(gen_out_dir)/main.h',
175 ],
200 'target_name': 'gen_ibus_mozc_files',
201 'type': 'none',
176202 'actions': [
177203 {
178204 'action_name': 'gen_main_h',
194220 },
195221 ],
196222 'dependencies': [
197 '../../base/base.gyp:base',
223 'gen_mozc_xml',
224 ],
225 },
226 {
227 'target_name': 'ibus_mozc',
228 'type': 'executable',
229 'sources': [
230 'main.cc',
231 '<(gen_out_dir)/main.h',
232 ],
233 'dependencies': [
234 '../../base/base.gyp:base',
235 'gen_ibus_mozc_files',
198236 'gen_mozc_xml',
199237 'ibus_mozc_lib',
200238 'ibus_mozc_metadata',
0 // Copyright 2010-2020, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 #include "unix/ibus/ibus_config.h"
30
31 #include "base/file_stream.h"
32 #include "base/file_util.h"
33 #include "base/logging.h"
34 #include "base/protobuf/text_format.h"
35 #include "base/system_util.h"
36 #include "unix/ibus/main.h"
37 #include "absl/strings/ascii.h"
38 #include "absl/strings/match.h"
39 #include "absl/strings/str_cat.h"
40 #include "absl/strings/str_replace.h"
41 #include "absl/strings/str_split.h"
42
43 namespace mozc {
44
45 constexpr char kIbusConfigFile[] = "ibus_config.textproto";
46
47 namespace {
48 std::string UpdateConfigFile() {
49 const std::string engines_file = FileUtil::JoinPath(
50 SystemUtil::GetUserProfileDirectory(), kIbusConfigFile);
51 if (FileUtil::FileExists(engines_file)) {
52 InputFileStream ifs(engines_file.c_str());
53 return ifs.Read();
54 } else {
55 OutputFileStream ofs(engines_file.c_str());
56 ofs << kIbusConfigTextProto;
57 ofs.close();
58 if (ofs.fail()) {
59 LOG(ERROR) << "Failed to write " << engines_file;
60 }
61 return kIbusConfigTextProto;
62 }
63 }
64
65 bool ParseConfig(const std::string &data, ibus::Config &config) {
66 if (mozc::protobuf::TextFormat::ParseFromString(data, &config)) {
67 return true;
68 }
69 // Failed to parse the data, fallback to the default setting.
70 mozc::protobuf::TextFormat::ParseFromString(kIbusConfigTextProto, &config);
71 return false;
72 }
73
74 std::string EscapeXmlValue(const std::string &value) {
75 return absl::StrReplaceAll(value, {{"&", "&amp;"},
76 {"<", "&lt;"},
77 {">", "&gt;"},
78 {"\"", "&quot;"},
79 {"'", "&apos;"}});
80 }
81
82 std::string CreateEnginesXml(const ibus::Config &config) {
83 std::string output = "<engines>\n";
84 for (const ibus::Engine &engine : config.engines()) {
85 absl::StrAppend(
86 &output,
87 "<engine>\n",
88 " <description>", kEngineDescription, "</description>\n",
89 " <language>", kEngineLanguage, "</language>\n",
90 " <icon>", kEngineIcon, "</icon>\n",
91 " <rank>", kEngineRank, "</rank>\n",
92 " <icon_prop_key>", kEngineIcon_prop_key, "</icon_prop_key>\n",
93 " <symbol>", kEngineSymbol, "</symbol>\n",
94 " <setup>", kEngineSetup, "</setup>\n",
95 " <name>", EscapeXmlValue(engine.name()), "</name>\n",
96 " <longname>", EscapeXmlValue(engine.longname()), "</longname>\n",
97 " <layout>", EscapeXmlValue(engine.layout()), "</layout>\n",
98 "</engine>\n");
99 }
100 absl::StrAppend(&output, "</engines>\n");
101 return output;
102 }
103 } // namespace
104
105 const std::string &IbusConfig::InitEnginesXml() {
106 const std::string config_data = UpdateConfigFile();
107 const bool valid_user_config = ParseConfig(config_data, config_);
108 engine_xml_ = CreateEnginesXml(config_);
109 if (!valid_user_config) {
110 engine_xml_ += ("<!-- Failed to parse the user config. -->\n"
111 "<!-- Used the default setting instead. -->\n");
112 }
113 return engine_xml_;
114 }
115
116 const ibus::Config &IbusConfig::GetConfig() const {
117 return config_;
118 }
119
120 const std::string &IbusConfig::GetLayout(const std::string& name) const {
121 for (const ibus::Engine &engine : config_.engines()) {
122 if (engine.name() == name) {
123 return engine.layout();
124 }
125 }
126 return default_layout_;
127 }
128 } // namespace mozc
0 // Copyright 2010-2020, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 #ifndef MOZC_UNIX_IBUS_IBUS_CONFIG_H_
30 #define MOZC_UNIX_IBUS_IBUS_CONFIG_H_
31
32 #include <map>
33 #include <string>
34
35 #include "unix/ibus/ibus_config.pb.h"
36
37 namespace mozc {
38
39 class IbusConfig {
40 public:
41 IbusConfig() : default_layout_("default") {}
42 virtual ~IbusConfig() = default;
43
44 // Disallow implicit constructors.
45 IbusConfig(const IbusConfig&) = delete;
46 IbusConfig& operator=(const IbusConfig&) = delete;
47
48 const std::string &InitEnginesXml();
49 const std::string &GetLayout(const std::string &name) const;
50 const ibus::Config &GetConfig() const;
51
52 private:
53 std::string default_layout_;
54 std::string engine_xml_;
55 ibus::Config config_;
56 };
57
58 } // namespace mozc
59
60 #endif // MOZC_UNIX_IBUS_IBUS_CONFIG_H_
0 // Copyright 2010-2020, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 syntax = "proto2";
30
31 package mozc.ibus;
32
33 message Config {
34 repeated Engine engines = 1;
35 }
36
37 message Engine {
38 optional string name = 1;
39 optional string longname = 2;
40 optional string layout = 3;
41 }
3333 #include "base/init_mozc.h"
3434 #include "base/logging.h"
3535 #include "base/version.h"
36 #include "unix/ibus/ibus_config.h"
3637 #include "unix/ibus/main.h"
3738 #include "unix/ibus/mozc_engine.h"
3839 #include "unix/ibus/path_util.h"
3940
4041 DEFINE_bool(ibus, false, "The engine is started by ibus-daemon");
42 DEFINE_bool(xml, false, "Output xml data for the engine.");
4143
4244 namespace {
4345
6971 mozc::Version::GetMozcVersion().c_str(), kComponentLicense,
7072 kComponentAuthor, kComponentHomepage, "", kComponentTextdomain);
7173 const std::string icon_path = mozc::ibus::GetIconPath(kEngineIcon);
72 for (size_t i = 0; i < kEngineArrayLen; ++i) {
74
75 mozc::IbusConfig ibus_config;
76 ibus_config.InitEnginesXml();
77 for (const mozc::ibus::Engine &engine : ibus_config.GetConfig().engines()) {
7378 ibus_component_add_engine(
7479 component,
75 ibus_engine_desc_new(kEngineNameArray[i], kEngineLongnameArray[i],
80 ibus_engine_desc_new(engine.name().c_str(), engine.longname().c_str(),
7681 kEngineDescription, kEngineLanguage,
7782 kComponentLicense, kComponentAuthor,
78 icon_path.c_str(), kEngineLayoutArray[i]));
83 icon_path.c_str(), engine.layout().c_str()));
7984 }
8085 return component;
8186 }
104109 g_object_unref(component);
105110 }
106111
112 void OutputXml() {
113 mozc::IbusConfig ibus_config;
114 std::cout << ibus_config.InitEnginesXml() << std::endl;
115 }
116
107117 } // namespace
108118
109119 int main(gint argc, gchar **argv) {
110120 mozc::InitMozc(argv[0], &argc, &argv);
121 if (mozc::GetFlag(FLAGS_xml)) {
122 OutputXml();
123 return 0;
124 }
125
111126 ibus_init();
112 InitIBusComponent(FLAGS_ibus);
127 InitIBusComponent(mozc::GetFlag(FLAGS_ibus));
113128 #ifndef MOZC_NO_LOGGING
114129 EnableVerboseLog();
115130 #endif // MOZC_NO_LOGGING
2626 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
29 #include <iostream>
30
31 #include "base/flags.h"
32 #include "base/init_mozc.h"
33 #include "unix/ibus/ibus_config.h"
34
35 DEFINE_bool(xml, false, "Output xml data for the engine.");
36
37 namespace {
38 void OutputXml() {
39 mozc::IbusConfig ibus_config;
40 std::cout << ibus_config.InitEnginesXml() << std::endl;
41 }
42 } // namespace
43
2944 int main(int argc, char **argv) {
45 mozc::InitMozc(argv[0], &argc, &argv);
46 if (mozc::GetFlag(FLAGS_xml)) {
47 OutputXml();
48 return 0;
49 }
50
3051 // This is a stub used by platforms which do not support iBus
3152 // (i.e. non Linux environments).
3253 return 1;
257257 }
258258 #endif // MOZC_ENABLE_X11_SELECTION_MONITOR
259259
260 ibus_config_.InitEnginesXml();
261
260262 // TODO(yusukes): write a unit test to check if the capability is set
261263 // as expected.
262264 }
348350 return FALSE;
349351 }
350352
351 // TODO(yusukes): use |layout| in IBusEngineDesc if possible.
352 const bool layout_is_jp = !g_strcmp0(ibus_engine_get_name(engine), "mozc-jp");
353 // layout_is_jp is only used determine Kana input with US layout.
354 const std::string &layout =
355 ibus_config_.GetLayout(ibus_engine_get_name(engine));
356 const bool layout_is_jp = (layout != "us");
353357
354358 commands::KeyEvent key;
355359 if (!key_event_handler_->GetKeyEvent(keyval, keycode, modifiers,
3737 #include "protocol/commands.pb.h"
3838 #include "testing/base/public/gunit_prod.h"
3939 #include "unix/ibus/engine_interface.h"
40 #include "unix/ibus/ibus_config.h"
4041
4142 namespace mozc {
4243
147148
148149 // Unique IDs of candidates that are currently shown.
149150 std::vector<int32> unique_candidate_ids_;
151 IbusConfig ibus_config_;
150152
151153 friend class LaunchToolTest;
152154 FRIEND_TEST(LaunchToolTest, LaunchToolTest);