Exemple #1
0
/**
 * update custom dict, if the dictionary of that language
 * cannot be found, keep the current one until the next successful loading.
 **/
boolean
SpellCustomLoadDict(FcitxSpell *spell, const char *lang)
{
    SpellCustomDict *custom_dict;
    if (spell->custom_saved_lang &&
        !strcmp(spell->custom_saved_lang, lang)) {
        free(spell->custom_saved_lang);
        spell->custom_saved_lang = NULL;
        return false;
    }
    custom_dict = SpellCustomNewDict(spell, lang);
    if (custom_dict) {
        if (spell->custom_saved_lang) {
            free(spell->custom_saved_lang);
            spell->custom_saved_lang = NULL;
        }
        if (spell->custom_dict)
            SpellCustomFreeDict(spell, spell->custom_dict);
        spell->custom_dict = custom_dict;
        return true;
    }
    if (!spell->custom_dict || !spell->dictLang)
        return false;
    if (spell->custom_saved_lang)
        return false;
    spell->custom_saved_lang = strdup(spell->dictLang);
    return false;
}
Exemple #2
0
void
SpellCustomDestroy(FcitxSpell *spell)
{
    if (spell->custom_dict)
        SpellCustomFreeDict(spell, spell->custom_dict);
    if (spell->custom_saved_lang)
        free(spell->custom_saved_lang);
}
SpellCustomDict*
SpellCustomNewDict(FcitxSpell *spell, const char *lang)
{
    SpellCustomDict *dict = fcitx_utils_new(SpellCustomDict);
    if (!SpellCustomInitDict(spell, dict, lang)) {
        SpellCustomFreeDict(spell, dict);
        return NULL;
    }
    return dict;
}