Ejemplo n.º 1
0
static int LoadLuaConfig(LuaModule *luamodule) {
    int count = 0;
    FcitxStringHashSet *sset = FcitxXDGGetFiles("lua", NULL, ".lua");
    FcitxStringHashSet *str;
    for (str = sset; str != NULL;) {
        FcitxStringHashSet *tmp = str->hh.next;
        char *path;
        FILE *f = FcitxXDGGetFileWithPrefix("lua", str->name, "r", &path);
        if (f && path) {
            if (LoadExtension(luamodule, path)) {
                FcitxLog(INFO, "lua load extension file:%s", path);
                ++count;
            } else {
                FcitxLog(ERROR, "LoadExtension() failed");
            }
        }
        if (f) {
            fclose(f);
        }
        if (path) {
            free(path);
        }
        HASH_DEL(sset, str);
        free(str->name);
        free(str);
        str = tmp;
    }
    return count;
}
Ejemplo n.º 2
0
FcitxYaTableInfo* FcitxYaTableGetAllCFG()
{
    FcitxYaTableInfo* head = NULL,* prev = NULL,* cur = NULL;
    FcitxStringHashSet* configfiles = FcitxXDGGetFiles("yatable", NULL,
                                      ".conf");

    HASH_FOREACH(file, configfiles, FcitxStringHashSet) {
        FcitxConfigFileDesc* cfgdesc = FcitxYaTableConfigDesc();
        if(cfgdesc == NULL) continue;

        FILE* fcfg = FcitxXDGGetFileWithPrefix("yatable", file->name, "r",
                                               NULL);
        if(fcfg == NULL) continue;

        FcitxConfigFile* cfgfile = FcitxConfigParseConfigFileFp(fcfg, cfgdesc);

        cur = fcitx_utils_malloc0(sizeof(FcitxYaTableInfo));
        cur->next = NULL;
        if(head == NULL) {
            head = cur;
        } else {
            prev->next = cur;
        }
        prev = cur;

        YaTableInfoConfigBind(&(cur->info), cfgfile, cfgdesc);
        FcitxConfigBindSync((FcitxGenericConfig*) &(cur->info));
        FcitxConfigFreeConfigFile(cfgfile);
        fclose(fcfg);

    }
Ejemplo n.º 3
0
void FileListModel::loadFileList()
{
    beginResetModel();
    m_fileList.clear();
    FcitxStringHashSet* files = FcitxXDGGetFiles(dictDir().toAscii().constData(), NULL, ".txt");

    HASH_SORT(files, fcitx_utils_string_hash_set_compare);
    HASH_FOREACH(f, files, FcitxStringHashSet) {
        m_fileList.append(QString::fromLocal8Bit(f->name).prepend(dictDir() + "/"));
    }
Ejemplo n.º 4
0
void fcitx::FileListModel::loadFileList() {
    beginResetModel();
    m_fileList.clear();
    m_fileList.append(QUICK_PHRASE_CONFIG_FILE);
    FcitxStringHashSet *files =
        FcitxXDGGetFiles(QUICK_PHRASE_CONFIG_DIR, NULL, ".mb");

    HASH_SORT(files, fcitx_utils_string_hash_set_compare);
    HASH_FOREACH(f, files, FcitxStringHashSet) {
        m_fileList.append(QString::fromLocal8Bit(f->name).prepend(
            QUICK_PHRASE_CONFIG_DIR "/"));
    }
Ejemplo n.º 5
0
Archivo: punc.c Proyecto: adaptee/fcitx
/**
 * 加载标点词典
 * @param void
 * @return void
 * @note 文件中数据的格式为: 对应的英文符号 中文标点 <中文标点>
 * 加载标点词典。标点词典定义了一组标点转换,如输入‘.’就直接转换成‘。’
 */
boolean LoadPuncDict(FcitxPuncState* puncState)
{
    FcitxStringHashSet* puncfiles = FcitxXDGGetFiles("data", PUNC_DICT_FILENAME "." , NULL);
    FcitxStringHashSet *curpuncfile = puncfiles;
    FcitxPunc* punc;
    while (curpuncfile) {
        punc = LoadPuncFile(curpuncfile->name);
        if (punc)
            HASH_ADD_KEYPTR(hh, puncState->puncSet, punc->langCode, strlen(punc->langCode), punc);
        curpuncfile = curpuncfile->hh.next;
    }

    fcitx_utils_free_string_hash_set(puncfiles);
    return true;
}
Ejemplo n.º 6
0
FcitxAddon* FcitxAddonsLoadInternal(UT_array* addons, boolean reloadIM)
{
    char **addonPath;
    size_t len;
    size_t start;
    if (!reloadIM)
        utarray_clear(addons);

    start = utarray_len(addons);

    FcitxStringHashSet* sset = FcitxXDGGetFiles("addon", NULL, ".conf");
    addonPath = FcitxXDGGetPathWithPrefix(&len, "addon");
    char *paths[len];
    HASH_FOREACH(string, sset, FcitxStringHashSet) {
        // FIXME: if it will cause realloc, then it's evil for fcitx 4.2 series
        if (reloadIM && addons->i == addons->n) {
            break;
        }
        
        int i;
        for (i = len - 1; i >= 0; i--) {
            fcitx_utils_alloc_cat_str(paths[i], addonPath[len - i - 1],
                                      "/", string->name);
            FcitxLog(DEBUG, "Load Addon Config File:%s", paths[i]);
        }
        FcitxConfigFile* cfile = FcitxConfigParseMultiConfigFile(paths, len, FcitxAddonGetConfigDesc());
        if (cfile) {
            utarray_extend_back(addons);
            FcitxAddon *a = (FcitxAddon*) utarray_back(addons);
            utarray_init(&a->functionList, fcitx_ptr_icd);
            FcitxAddonConfigBind(a, cfile, FcitxAddonGetConfigDesc());
            FcitxConfigBindSync((FcitxGenericConfig*)a);
            FcitxLog(DEBUG, _("Addon Config %s is %s"), string->name, (a->bEnabled) ? "Enabled" : "Disabled");
            boolean error = false;
            if (reloadIM) {
                if (a->category !=  AC_INPUTMETHOD)
                    error = true;
            }
            /* if loaded, don't touch the old one */
            if (FcitxAddonsGetAddonByNameInternal(addons, a->name, true) != a)
                error = true;

            if (error)
                utarray_pop_back(addons);
            else
                FcitxLog(INFO, _("Load Addon Config File:%s"), string->name);
        }

        for (i = len - 1;i >= 0;i--) {
            free(paths[i]);
        }
    }
    FcitxXDGFreePath(addonPath);

    fcitx_utils_free_string_hash_set(sset);

    size_t to = utarray_len(addons);
    utarray_sort_range(addons, AddonPriorityCmp, start, to);

    return (FcitxAddon*)utarray_eltptr(addons, start);
}