void _CloudPinyinAddCandidateWord(FcitxCloudPinyin* cloudpinyin, const char* pinyin) { CloudPinyinCache* cacheEntry = CloudPinyinCacheLookup(cloudpinyin, pinyin); FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input); int order = (cloudpinyin->config.iCandidateOrder <= 2) ? 1 : (cloudpinyin->config.iCandidateOrder - 1); if (cacheEntry) { FcitxCandidateWord* cand; /* only check the first three page */ int pagesize = FcitxCandidateWordGetPageSize(candList); int size = pagesize * CLOUDPINYIN_CHECK_PAGE_NUMBER; int i; if (cloudpinyin->config.iCandidateOrder <= 1) { order = 0; } for (i = 0;i < size && (cand = FcitxCandidateWordGetByTotalIndex(candList, i));i++) { if (strcmp(cand->strWord, cacheEntry->str) == 0) { if (i > order && i >= pagesize) { FcitxCandidateWordMoveByWord(candList, cand, order); if (order == 0) { CloudSetClientPreedit(cloudpinyin, cacheEntry->str); } } return; } } if (order == 0) { CloudSetClientPreedit(cloudpinyin, cacheEntry->str); } } FcitxCandidateWord candWord; CloudCandWord* cloudCand = fcitx_utils_malloc0(sizeof(CloudCandWord)); if (cacheEntry) { cloudCand->filled = true; cloudCand->timestamp = 0; candWord.strWord = strdup(cacheEntry->str); } else { cloudCand->filled = false; cloudCand->timestamp = CloudGetTimeStamp(); candWord.strWord = strdup(".."); } candWord.callback = CloudPinyinGetCandWord; candWord.owner = cloudpinyin; candWord.priv = cloudCand; candWord.wordType = MSG_TIPS; if (cloudpinyin->config.bDontShowSource) candWord.strExtra = NULL; else { candWord.strExtra = strdup(_(" (via cloud)")); candWord.extraType = MSG_TIPS; } FcitxCandidateWordInsert(candList, &candWord, order); }
void _CloudPinyinAddCandidateWord(FcitxCloudPinyin* cloudpinyin, const char* pinyin) { CloudPinyinCache* cacheEntry = CloudPinyinCacheLookup(cloudpinyin, pinyin); FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); struct _FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input); if (cacheEntry) { FcitxCandidateWord* cand; /* only check the first three page */ int size = FcitxCandidateWordGetPageSize(candList) * CLOUDPINYIN_CHECK_PAGE_NUMBER; int i = 0; for (cand = FcitxCandidateWordGetFirst(FcitxInputStateGetCandidateList(input)); cand != NULL; cand = FcitxCandidateWordGetNext(FcitxInputStateGetCandidateList(input), cand)) { if (strcmp(cand->strWord, cacheEntry->str) == 0) return; i ++; if (i >= size) break; } } FcitxCandidateWord candWord; CloudCandWord* cloudCand = fcitx_utils_malloc0(sizeof(CloudCandWord)); if (cacheEntry) { cloudCand->filled = true; candWord.strWord = strdup(cacheEntry->str); } else { cloudCand->filled = false; candWord.strWord = strdup(".."); } candWord.callback = CloudPinyinGetCandWord; candWord.owner = cloudpinyin; candWord.priv = cloudCand; candWord.wordType = MSG_TIPS; if (cloudpinyin->config.bDontShowSource) candWord.strExtra = NULL; else { candWord.strExtra = strdup(_(" (via cloud)")); candWord.extraType = MSG_TIPS; } int order = cloudpinyin->config.iCandidateOrder - 1; if (order < 0) order = 0; FcitxCandidateWordInsert(candList, &candWord, order); }
void AddToCandList(LuaModule *luamodule, const char *in, const char *out) { FcitxCandidateWord candWord; candWord.callback = LuaGetCandWord; candWord.owner = luamodule; candWord.priv = NULL; candWord.wordType = MSG_TIPS; candWord.strExtra = NULL; candWord.strWord = strdup(out); FcitxInputState* input = FcitxInstanceGetInputState(GetFcitx(luamodule)); FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input); FcitxCandidateWordInsert(candList, &candWord, 0); }