示例#1
0
/**
 * @brief Load one keyboard ISE module.
 *
 * @param module_name The keboard ISE module name.
 * @param config The config pointer for loading keyboard ISE.
 *
 * @return true if load module is successful, otherwise return false.
 */
static bool add_keyboard_ise_module (const String module_name, const ConfigPointer &config)
{
    if (module_name.length () <= 0 || module_name == "socket")
        return false;

    IMEngineFactoryPointer factory;
    IMEngineModule         ime_module;

    String filename = String (USER_ENGINE_FILE_NAME);
    FILE *engine_list_file = fopen (filename.c_str (), "a");
    if (engine_list_file == NULL) {
        std::cerr << "failed to open " << filename << "\n";
        return false;
    }

    ime_module.load (module_name, config);
    if (ime_module.valid ()) {
        for (size_t j = 0; j < ime_module.number_of_factories (); ++j) {
            try {
                factory = ime_module.create_factory (j);
            } catch (...) {
                factory.reset ();
            }

            if (!factory.null ()) {
                if (std::find (_uuids.begin (), _uuids.end (), factory->get_uuid ()) == _uuids.end ()) {
                    String uuid = factory->get_uuid ();
                    String name = utf8_wcstombs (factory->get_name ());
                    String language = isf_get_normalized_language (factory->get_language ());
                    String icon = factory->get_icon_file ();
                    char mode[12];
                    char option[12];

                    _uuids.push_back (uuid);
                    _names.push_back (name);
                    _module_names.push_back (module_name);
                    _langs.push_back (language);
                    _icons.push_back (icon);
                    _modes.push_back (TOOLBAR_KEYBOARD_MODE);
                    _options.push_back (0);

                    snprintf (mode, sizeof (mode), "%d", (int)TOOLBAR_KEYBOARD_MODE);
                    snprintf (option, sizeof (option), "%d", 0);

                    String line = isf_combine_ise_info_string (name, uuid, module_name, language, 
                                                               icon, String (mode), String (option), factory->get_locales ());
                    if (fputs (line.c_str (), engine_list_file) < 0) {
                        std::cerr << "write to ise cache file failed:" << line << "\n";
                        break;
                    }
                }
                factory.reset ();
            }
        }
        ime_module.unload ();
    }

    fclose (engine_list_file);

    return true;
}