示例#1
0
static void add_keyboard_info_to_list (std::vector<ISEINFO> &info_list, const char *module_name, const ConfigPointer &config)
{
    if (module_name == NULL)
        return;

    IMEngineFactoryPointer factory;
    IMEngineModule         ime_module;
    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 ()) {
                ISEINFO info;

                info.name = utf8_wcstombs (factory->get_name ());
                info.uuid = factory->get_uuid ();
                info.module = module_name;
                info.language = isf_get_normalized_language (factory->get_language ());
                info.icon = factory->get_icon_file ();
                info.mode = TOOLBAR_KEYBOARD_MODE;
                info.option = 0;
                info.locales = factory->get_locales ();

                info_list.push_back (info);
                factory.reset ();
            }
        }
        ime_module.unload ();
    }
}
示例#2
0
/**
 * @brief Load all ISEs to initialize.
 *
 * @param type The loading ISE type.
 * @param config The config pointer for loading keyboard ISE.
 * @param uuids The ISE uuid list.
 * @param names The ISE name list.
 * @param module_names The ISE module name list.
 * @param langs The ISE language list.
 * @param icons The ISE icon list.
 * @param modes The ISE type list.
 * @param options The ISE option list.
 * @param ise_list The already loaded ISE list.
 */
void isf_get_factory_list (LOAD_ISE_TYPE  type,
                           const ConfigPointer &config,
                           std::vector<String> &uuids,
                           std::vector<String> &names,
                           std::vector<String> &module_names,
                           std::vector<String> &langs,
                           std::vector<String> &icons,
                           std::vector<TOOLBAR_MODE_T> &modes,
                           std::vector<uint32> &options,
                           const std::vector<String> &ise_list)
{
    uuids.clear ();
    names.clear ();
    module_names.clear ();
    langs.clear ();
    icons.clear ();
    modes.clear ();
    options.clear ();
    _groups.clear ();

    if (type != HELPER_ONLY) {
        /* Add "English/Keyboard" factory first. */
        IMEngineFactoryPointer factory = new ComposeKeyFactory ();
        uuids.push_back (factory->get_uuid ());
        names.push_back (utf8_wcstombs (factory->get_name ()));
        module_names.push_back (ENGLISH_KEYBOARD_MODULE);
        langs.push_back (isf_get_normalized_language (factory->get_language ()));
        icons.push_back (factory->get_icon_file ());
        modes.push_back (TOOLBAR_KEYBOARD_MODE);
        options.push_back (0);
        factory.reset ();
    }

    String user_file_name = String (USER_ENGINE_FILE_NAME);
    FILE *engine_list_file = fopen (user_file_name.c_str (), "r");
    if (engine_list_file == NULL) {
        std::cerr <<  user_file_name << " doesn't exist.\n";
        return;
    }

    char buf[MAXLINE];
    while (fgets (buf, MAXLINE, engine_list_file) != NULL) {
        ISEINFO info;
        isf_get_ise_info_from_string (buf, info);
        if (info.mode == TOOLBAR_HELPER_MODE || type != HELPER_ONLY) {
            names.push_back (info.name);
            uuids.push_back (info.uuid);
            module_names.push_back (info.module);
            langs.push_back (info.language);
            icons.push_back (info.icon);
            modes.push_back (info.mode);
            options.push_back (info.option);
        }
    }

    fclose (engine_list_file);
}
示例#3
0
 void scim_module_exit (void)
 {
     _scim_pinyin_factory.reset ();
     _scim_config.reset ();
 }
示例#4
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;
}