Пример #1
0
String
scim_get_language_locales (const String &lang)
{
    __Language *result = __find_language (lang);

    std::vector<String> locales;

    if (result) {
        String good;

        if (strlen (result->code) < 5 && result->normalized)
            result = __find_language (result->normalized);

        good = scim_validate_locale (String (result->code) + ".UTF-8");

        if (good.length ()) locales.push_back (good);

        if (result->locale_suffix) {
            std::vector<String> suffixes;

            scim_split_string_list (suffixes, result->locale_suffix, ',');
            for (size_t i = 0; i < suffixes.size (); ++ i) {
                good = scim_validate_locale (String (result->code) + suffixes [i]);
                if (good.length ()) locales.push_back (good);
            }
        }

        good = scim_validate_locale (result->code);

        if (good.length ()) locales.push_back (good);
    }

    return scim_combine_string_list (locales, ',');
}
Пример #2
0
String
scim_get_locale_encoding (const String& locale)
{
    String last = String (setlocale (LC_CTYPE, 0));
    String encoding;

    if (setlocale (LC_CTYPE, locale.c_str ()))
        encoding = String (nl_langinfo (CODESET));
    else {
        std::vector<String> vec;
        if (scim_split_string_list (vec, locale, '.') == 2) {
            if (isupper (vec[1][0])) {
                for (String::iterator i=vec[1].begin (); i!=vec[1].end (); ++i) 
                    *i = (char) tolower (*i);
            } else {
                for (String::iterator i=vec[1].begin (); i!=vec[1].end (); ++i) 
                    *i = (char) toupper (*i);
            }
            if (setlocale (LC_CTYPE, (vec[0] + "." + vec[1]).c_str ()))
                encoding = String (nl_langinfo (CODESET));
        }
        
    }

    setlocale (LC_CTYPE, last.c_str ());

    return encoding;
}
Пример #3
0
/**
 * @brief Load all ISEs information and ISF default languages.
 *
 * @param type The load ISE type.
 * @param config The config pointer for loading keyboard ISE.
 */
void isf_load_ise_information (LOAD_ISE_TYPE  type, const ConfigPointer &config)
{
    /* Load ISE engine info */
    isf_get_factory_list (type, config, _uuids, _names, _module_names, _langs, _icons, _modes, _options, _load_ise_list);

    _current_modules_list.clear ();
    scim_get_helper_module_list (_current_modules_list);
    /* Check keyboard ISEs */
    if (type != HELPER_ONLY) {
        _current_modules_list.push_back (ENGLISH_KEYBOARD_MODULE);
        std::vector<String> imengine_list;
        scim_get_imengine_module_list (imengine_list);
        for (size_t i = 0; i < imengine_list.size (); ++i)
            _current_modules_list.push_back (imengine_list [i]);
    }

    /* Update _groups */
    std::vector<String> ise_langs;
    for (size_t i = 0; i < _uuids.size (); ++i) {
        scim_split_string_list (ise_langs, _langs[i]);
        for (size_t j = 0; j < ise_langs.size (); j++) {
            if (std::find (_groups[ise_langs[j]].begin (), _groups[ise_langs[j]].end (), i) == _groups[ise_langs[j]].end ())
                _groups[ise_langs[j]].push_back (i);
        }
        ise_langs.clear ();
    }
}
Пример #4
0
String
scim_validate_locale (const String& locale)
{
    String good;

    String last = String (setlocale (LC_CTYPE, 0));

    if (setlocale (LC_CTYPE, locale.c_str ())) {
        good = locale;
    } else {
        std::vector<String> vec;
        if (scim_split_string_list (vec, locale, '.') == 2) {
            if (isupper (vec[1][0])) {
                for (String::iterator i=vec[1].begin (); i!=vec[1].end (); ++i) 
                    *i = (char) tolower (*i);
            } else {
                for (String::iterator i=vec[1].begin (); i!=vec[1].end (); ++i) 
                    *i = (char) toupper (*i);
            }
            if (setlocale (LC_CTYPE, (vec[0] + "." + vec[1]).c_str ())) {
                good = vec [0] + "." + vec[1];
            }
        }
    }

    setlocale (LC_CTYPE, last.c_str ());

    return good;
}
Пример #5
0
//int list
bool
SimpleConfig::read (const String& key, std::vector <int>* val) const
{
    if (!valid () || !val || key.empty()) return false;

    KeyValueRepository::const_iterator i = m_new_config.find (key);
    KeyValueRepository::const_iterator end = m_new_config.end ();

    if (i == end) {
        i = m_config.find (key);
        end = m_config.end ();
    }

    val->clear();

    if (i != end) {
        std::vector <String> vec;
        scim_split_string_list (vec, i->second, ',');

        for (std::vector <String>::iterator j = vec.begin (); j != vec.end (); ++j) {
            int result = strtol (j->c_str (), (char**)NULL, 10);
            val->push_back (result);
        }
        return true;
    }

    return false;
}
Пример #6
0
bool
SimpleConfig::load_all_config ()
{
    String sysconf = get_sysconf_filename ();
    String userconf = get_userconf_filename ();

    KeyValueRepository config;

    if (userconf.length ()) {
        std::ifstream is (userconf.c_str ());
        if (is) {
            SCIM_DEBUG_CONFIG(1) << "Parsing user config file: "
                                 << userconf << "\n";
            parse_config (is, config);
        }
    }

    if (sysconf.length ()) {
        std::ifstream is (sysconf.c_str ());
        if (is) {
            SCIM_DEBUG_CONFIG(1) << "Parsing system config file: "
                                 << sysconf << "\n";
            parse_config (is, config);
        }
    }

    if (!m_config.size () || (m_update_timestamp.tv_sec == 0 && m_update_timestamp.tv_usec == 0)) {
        m_config.swap (config);
        gettimeofday (&m_update_timestamp, 0);
        return true;
    }

    KeyValueRepository::iterator it = config.find (String (SCIM_CONFIG_UPDATE_TIMESTAMP));

    if (it != config.end ()) {
        std::vector <String> strs;
        if (scim_split_string_list (strs, it->second, ':') == 2) {
            time_t sec = (time_t) strtol (strs [0].c_str (), 0, 10);
            suseconds_t usec = (suseconds_t) strtol (strs [1].c_str (), 0, 10);

            // The config file is newer, so load it.
            if (m_update_timestamp.tv_sec < sec || (m_update_timestamp.tv_sec == sec && m_update_timestamp.tv_usec < usec)) {
                m_config.swap (config);
                m_update_timestamp.tv_sec = (time_t) sec;
                m_update_timestamp.tv_usec = (suseconds_t) usec;
                return true;
            }
        }
    }
    return false;
}
Пример #7
0
/**
 * @brief Update ISEs information for ISE is added or removed.
 *
 * @param type The load ISE type.
 * @param config The config pointer for loading keyboard ISE.
 *
 * @return true if ISEs list is changed, otherwise return false.
 */
bool isf_update_ise_list (LOAD_ISE_TYPE type, const ConfigPointer &config)
{
    bool ret = false;

    std::vector<String> helper_list;
    scim_get_helper_module_list (helper_list);

    _current_modules_list.clear ();

    /* Check keyboard ISEs */
    if (type != HELPER_ONLY) {
        _current_modules_list.push_back (ENGLISH_KEYBOARD_MODULE);
        std::vector<String> imengine_list;
        scim_get_imengine_module_list (imengine_list);
        for (size_t i = 0; i < imengine_list.size (); ++i) {
            _current_modules_list.push_back (imengine_list [i]);
            if (std::find (_module_names.begin (), _module_names.end (), imengine_list [i]) == _module_names.end ()) {
                if (add_keyboard_ise_module (imengine_list [i], config))
                    ret = true;
            }
        }
    }

    /* Check helper ISEs */
    for (size_t i = 0; i < helper_list.size (); ++i) {
        _current_modules_list.push_back (helper_list [i]);
        if (std::find (_module_names.begin (), _module_names.end (), helper_list [i]) == _module_names.end ()) {
            if (add_helper_ise_module (helper_list [i]))
                ret = true;
        }
    }

    /* Update _groups */
    if (ret) {
        std::vector<String> ise_langs;
        for (size_t i = 0; i < _uuids.size (); ++i) {
            scim_split_string_list (ise_langs, _langs[i]);
            for (size_t j = 0; j < ise_langs.size (); j++) {
                if (std::find (_groups[ise_langs[j]].begin (), _groups[ise_langs[j]].end (), i) == _groups[ise_langs[j]].end ())
                    _groups[ise_langs[j]].push_back (i);
            }
            ise_langs.clear ();
        }
    }

    /* When load ise list is empty, all ISEs can be loaded. */
    _load_ise_list.clear ();
    return ret;
}
Пример #8
0
bool
scim_make_dir (const String &dir)
{
    std::vector <String> paths;
    String path;

    scim_split_string_list (paths, dir, SCIM_PATH_DELIM);
 
    for (size_t i = 0; i < paths.size (); ++i) {
        path += SCIM_PATH_DELIM_STRING + paths [i];

        //Make the dir if it's not exist.
        if (access (path.c_str (), R_OK) != 0) {
            mkdir (path.c_str (), S_IRUSR | S_IWUSR | S_IXUSR);
            if (access (path.c_str (), R_OK) != 0)
                return false;
        }
    }
    return true;
}
Пример #9
0
//String list
bool
SimpleConfig::read (const String& key, std::vector <String>* val) const
{
    if (!valid () || !val || key.empty()) return false;
    
    KeyValueRepository::const_iterator i = m_new_config.find (key);
    KeyValueRepository::const_iterator end = m_new_config.end ();

    if (i == end) {
        i = m_config.find (key);
        end = m_config.end ();
    }

    val->clear ();

    if (i != end) {
        scim_split_string_list (*val, i->second, ',');
        return true;
    }

    return false;
}
Пример #10
0
void
IMEngineHotkeyMatcher::load_hotkeys (const ConfigPointer &config)
{
    clear ();

    if (config.null () || !config->valid ()) return;

    std::vector <String> uuids;

    scim_split_string_list (uuids, config->read (String (SCIM_CONFIG_HOTKEYS_IMENGINE_LIST), String ("")));

    std::sort (uuids.begin (), uuids.end ());
    uuids.erase (std::unique (uuids.begin (), uuids.end ()), uuids.end ());

    if (uuids.size ()) {
        KeyEventList keys;
        for (std::vector <String>::iterator uit = uuids.begin (); uit != uuids.end (); ++uit) {
            if (scim_string_to_key_list (keys, config->read (String (SCIM_CONFIG_HOTKEYS_IMENGINE "/") + *uit, String ("")))) {
                m_impl->m_matcher.add_hotkeys (keys, (int) m_impl->m_uuids.size ());
                m_impl->m_uuids.push_back (*uit);
            }
        }
    }
}