* Sets the engine designed by its name to be the global engine */
| 232 | * Sets the engine designed by its name to be the global engine |
| 233 | */ |
| 234 | bool IBusHandler::ActivateEngine(const std::string& engine_name) { |
| 235 | if (! ibus_available_) { |
| 236 | return false; |
| 237 | } |
| 238 | |
| 239 | bool retval = false; |
| 240 | |
| 241 | std::vector<std::string> available_engines = GetInstalledEngines(); |
| 242 | // We activate only the engines that were preloaded or loaded by a call to |
| 243 | // LoadEngines before to ensure a valid state of the ibus system. |
| 244 | if (std::find(available_engines.begin(), available_engines.end(), engine_name) |
| 245 | != available_engines.end()) { |
| 246 | retval = ibus_bus_set_global_engine(bus_, engine_name.c_str()); |
| 247 | } |
| 248 | |
| 249 | IBusInputContext* context = GetCurrentInputContext(); |
| 250 | if ((retval) && (context != NULL)) { |
| 251 | ibus_input_context_enable(context); |
| 252 | } |
| 253 | |
| 254 | return retval; |
| 255 | } |
| 256 | |
| 257 | /* To use the library with dlopen. */ |
| 258 | extern "C" { |