void FcitxNotificationItemGetToolTip(void* arg, DBusMessageIter* iter) { FcitxNotificationItem* notificationitem = (FcitxNotificationItem*) arg; DBusMessageIter sub, ssub; char* iconNameToFree = NULL, *iconName, *title, *content; dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, 0, &sub); FcitxInputContext* ic = FcitxInstanceGetCurrentIC(notificationitem->owner); if (ic == NULL) { iconName = "input-keyboard"; title = _("No input window"); content = ""; } else { iconName = FcitxNotificationItemGetIconNameString(notificationitem); iconNameToFree = iconName; FcitxIM* im = FcitxInstanceGetCurrentIM(notificationitem->owner); title = im ? im->strName : _("Disabled"); content = im ? "" : _("Input Method Disabled"); } dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &iconName); dbus_message_iter_open_container(&sub, DBUS_TYPE_ARRAY, "(iiay)", &ssub); dbus_message_iter_close_container(&sub, &ssub); dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &title); dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &content); dbus_message_iter_close_container(iter, &sub); fcitx_utils_free(iconNameToFree); }
char* ChttransOutputFilter(void* arg, const char *strin) { FcitxChttrans* transState = (FcitxChttrans*) arg; FcitxIM* im = FcitxInstanceGetCurrentIM(transState->owner); /* don't trans for "zh" */ if (!im || strncmp(im->langCode, "zh", 2) != 0 || strlen(im->langCode) == 2) return NULL; if (ChttransEnabled(transState)) { if (strcmp(im->langCode, "zh_HK") == 0 || strcmp(im->langCode, "zh_TW") == 0) { return NULL; } else { return ConvertGBKSimple2Tradition(transState, strin); } } else { if (strcmp(im->langCode, "zh_CN") == 0) { return NULL; } else { return ConvertGBKTradition2Simple(transState, strin); } } return NULL; }
void CloudPinyinAddCandidateWord(void* arg) { FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg; FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); if (cloudpinyin->initialized == false) return; /* check whether the current im is pinyin */ if (CHECK_VALID_IM) { /* there is something pending input */ if (FcitxInputStateGetRawInputBufferSize(input) >= cloudpinyin->config.iMinimumPinyinLength) { char* strToFree = NULL, *inputString; strToFree = GetCurrentString(cloudpinyin); inputString = SplitHZAndPY(strToFree); if (inputString) { CloudPinyinCache* cacheEntry = CloudPinyinCacheLookup(cloudpinyin, inputString); FcitxLog(LOGLEVEL, "%s", inputString); if (cacheEntry == NULL) CloudPinyinAddInputRequest(cloudpinyin, inputString); _CloudPinyinAddCandidateWord(cloudpinyin, inputString); } if (strToFree) free(strToFree); } } return; }
boolean PostInputProcessAutoEng(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retval) { FcitxAutoEngState* autoEngState = (FcitxAutoEngState*) arg; FcitxInputState* input = FcitxInstanceGetInputState(autoEngState->owner); //boolean disableCheckUAZ = FcitxInstanceGetContextBoolean(autoEngState->owner, CONTEXT_DISABLE_AUTOENG); //if (disableCheckUAZ) // return false; if (autoEngState->enable == false) return false; FcitxIM *im = FcitxInstanceGetCurrentIM(autoEngState->owner); if (im == NULL || strcmp("sogoupinyin", im->uniqueName) != 0) return false; if (FcitxHotkeyIsHotKeyUAZ(sym, state) && (FcitxInputStateGetRawInputBufferSize(input) != 0 || (FcitxInputStateGetKeyState(input) & FcitxKeyState_CapsLock) == 0) && AutoEngCheckPreedit(autoEngState)) { AutoEngSetBuff(autoEngState, FcitxInputStateGetRawInputBuffer(input), FcitxHotkeyPadToMain(sym)); AutoEngActivate(autoEngState, input, retval); return true; } return false; }
boolean MainMenuAction(FcitxUIMenu* menu, int index) { FcitxClassicUI* classicui = (FcitxClassicUI*) menu->priv; FcitxInstance* instance = classicui->owner; int length = utarray_len(&menu->shell); if (index == 0) { char* args[] = { "xdg-open", "http://fcitx-im.org/", 0 }; fcitx_utils_start_process(args); } else if (index == length - 1) { /* Exit */ FcitxInstanceEnd(classicui->owner); } else if (index == length - 2) { /* Restart */ fcitx_utils_launch_restart(); } else if (index == length - 3) { /* Configuration */ fcitx_utils_launch_configure_tool(); } else if (index == length - 4) { /* Configuration */ FcitxIM* im = FcitxInstanceGetCurrentIM(classicui->owner); if (im && im->owner) { fcitx_utils_launch_configure_tool_for_addon(im->uniqueName); } else { fcitx_utils_launch_configure_tool(); } } else { FcitxMenuItem* item = (FcitxMenuItem*) utarray_eltptr(&menu->shell, index); if (item && item->type == MENUTYPE_SIMPLE && item->data) { const char* name = item->data; FcitxUIUpdateStatus(instance, name); } } return true; }
void ChttransIMChanged(void* arg) { FcitxChttrans* transState = (FcitxChttrans*) arg; FcitxIM* im = FcitxInstanceGetCurrentIM(transState->owner); if (!im) return; FcitxUIRefreshStatus(transState->owner, "chttrans"); }
void IMSelectorGetCands(IMSelector* imselector) { FcitxInstance* instance = imselector->owner; FcitxInputState *input = FcitxInstanceGetInputState(instance); UT_array* imes = FcitxInstanceGetIMEs(instance); FcitxInstanceCleanInputWindow(instance); FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input); FcitxCandidateWordSetPageSize(candList, 10); FcitxCandidateWordSetChoose(candList, DIGIT_STR_CHOOSE); FcitxInputStateSetShowCursor(input, false); FcitxCandidateWordSetOverrideDefaultHighlight(candList, false); FcitxCandidateWordSetLayoutHint(candList, CLH_Vertical); FcitxIM* im = FcitxInstanceGetCurrentIM(instance); FcitxInputContext* ic = FcitxInstanceGetCurrentIC(instance); FcitxInputContext2* ic2 = (FcitxInputContext2*) ic; if (!ic) return; FcitxMessages *aux_up = FcitxInputStateGetAuxUp(input); FcitxMessagesAddMessageStringsAtLast(aux_up, MSG_TIPS, imselector->global ? _("Select global input method: ") : _("Select local input method: ")); if (ic2->imname) { int idx = FcitxInstanceGetIMIndexByName(instance, ic2->imname); FcitxIM *im = fcitx_array_eltptr(imes, idx); if (im) { FcitxMessagesAddMessageStringsAtLast(aux_up, MSG_TIPS, _("Current local input method is "), im->strName); } } else { FcitxMessagesAddMessageStringsAtLast(aux_up, MSG_TIPS, _("No local input method")); } utarray_foreach(pim, imes, FcitxIM) { FcitxCandidateWord candWord; candWord.callback = IMSelectorGetCand; candWord.owner = imselector; candWord.strExtra = NULL; if (ic2->imname && strcmp(ic2->imname, pim->uniqueName) == 0) { candWord.priv = NULL; candWord.strWord = strdup(_("Clear local input method")); } else { candWord.priv = strdup(pim->uniqueName); candWord.strWord = strdup(pim->strName); } if (im && strcmp(im->uniqueName, pim->uniqueName) == 0) { candWord.wordType = MSG_CANDIATE_CURSOR; } else { candWord.wordType = MSG_OTHER; } FcitxCandidateWordAppend(candList, &candWord); }
static boolean PreInputProcessAutoEng(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE *retval) { FcitxAutoEngState *autoEngState = (FcitxAutoEngState*)arg; FcitxInputState *input = FcitxInstanceGetInputState(autoEngState->owner); //boolean disableCheckUAZ = FcitxInstanceGetContextBoolean( // autoEngState->owner, CONTEXT_DISABLE_AUTOENG); //if (disableCheckUAZ) // return false; if (autoEngState->enable == false) return false; FcitxIM *im = FcitxInstanceGetCurrentIM(autoEngState->owner); if (im == NULL || strcmp("sogoupinyin", im->uniqueName) != 0) return false; FcitxKeySym keymain = FcitxHotkeyPadToMain(sym); if (!autoEngState->active) { if (FcitxHotkeyIsHotKeySimple(sym, state)) { AutoEngSetBuff(autoEngState, FcitxInputStateGetRawInputBuffer(input), keymain); if (SwitchToEng(autoEngState, autoEngState->buf)) { AutoEngActivate(autoEngState, input, retval); return true; } } return false; } if ((*retval = AutoEngCheckSelect(autoEngState, sym, state))) { return true; } else if (FcitxHotkeyIsHotKeySimple(keymain, state)) { *retval = AutoEngPushKey(autoEngState, keymain); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) { AutoEngSetBuffLen(autoEngState, --autoEngState->index); if (autoEngState->index == 0) { ResetAutoEng(autoEngState); *retval = IRV_CLEAN; } else { *retval = IRV_DISPLAY_MESSAGE; } } else if (FcitxHotkeyIsHotkeyCursorMove(sym, state)) { *retval = IRV_DO_NOTHING; return true; } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) { AutoEngCommit(autoEngState); ResetAutoEng(autoEngState); *retval = IRV_FLAG_UPDATE_INPUT_WINDOW | IRV_FLAG_RESET_INPUT; } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) { *retval = IRV_CLEAN; return true; } ShowAutoEngMessage(autoEngState, retval); return true; }
void FcitxKkcResetHook(void *arg) { FcitxKkc *kkc = (FcitxKkc*)arg; FcitxIM* im = FcitxInstanceGetCurrentIM(kkc->owner); #define RESET_STATUS(STATUS_NAME) \ if (im && strcmp(im->uniqueName, "kkc") == 0) \ FcitxUISetStatusVisable(kkc->owner, STATUS_NAME, true); \ else \ FcitxUISetStatusVisable(kkc->owner, STATUS_NAME, false); RESET_STATUS("kkc-input-mode") }
static boolean ChttransEnabled(FcitxChttrans* chttrans) { boolean result = false; FcitxIM* im = FcitxInstanceGetCurrentIM(chttrans->owner); if (im) { boolean defaultValue = false; if (strcmp(im->langCode, "zh_TW") == 0 || strcmp(im->langCode, "en_HK") == 0 || strcmp(im->langCode, "zh_HK") == 0) { defaultValue = true; } result = fcitx_string_map_get(chttrans->enableIM, im->uniqueName, defaultValue); } return result; }
const char* FcitxNotificationItemGetLabel(FcitxNotificationItem* notificationitem) { const char* label = ""; #if 0 FcitxInputContext* ic = FcitxInstanceGetCurrentIC(notificationitem->owner); if (ic) { FcitxIM* im = FcitxInstanceGetCurrentIM(notificationitem->owner); if (im) { label = im->strName; } } #endif return label; }
void ToggleChttransState(void* arg) { FcitxChttrans* transState = (FcitxChttrans*) arg; FcitxIM* im = FcitxInstanceGetCurrentIM(transState->owner); if (!im) return; boolean enabled = !ChttransEnabled(transState); fcitx_string_map_set(transState->enableIM, im->uniqueName, enabled); FcitxUISetStatusString(transState->owner, "chttrans", enabled ? _("Traditional Chinese") : _("Simplified Chinese"), _("Toggle Simp/Trad Chinese Conversion")); FcitxUIUpdateInputWindow(transState->owner); SaveChttransConfig(transState); }
void ResetAutoEng(void *arg) { FcitxAutoEngState *autoEngState = (FcitxAutoEngState*)arg; if (autoEngState->enable == false) return; FcitxIM *im = FcitxInstanceGetCurrentIM(autoEngState->owner); if (im == NULL || strcmp("sogoupinyin", im->uniqueName) != 0) return; autoEngState->index = 0; AutoEngSetBuffLen(autoEngState, 0); autoEngState->active = false; autoEngState->cursor_moved = false; }
SkinImage* GetIMIcon(FcitxClassicUI* classicui, FcitxSkin *sc, const char* fallbackIcon, int flag, boolean fallbackToDefault) { FcitxIM* im = FcitxInstanceGetCurrentIM(classicui->owner); if (!im) return NULL; const char *path; char *tmpstr = NULL; if (im->strIconName[0] == '/') { path = im->strIconName; } else { fcitx_utils_alloc_cat_str(tmpstr, im->strIconName, ".png"); path = tmpstr; } SkinImage *imicon = NULL; if (strncmp(im->uniqueName, "fcitx-keyboard-", strlen("fcitx-keyboard-")) == 0) { SkinImage* activeIcon = LoadImage(sc, fallbackIcon, fallbackToDefault); char temp[LANGCODE_LENGTH + 1] = { '\0', }; char* iconText = 0; if (*im->langCode) { strncpy(temp, im->langCode, LANGCODE_LENGTH); iconText = temp; iconText[0] = toupper(iconText[0]); } else { iconText = im->uniqueName + strlen("fcitx-keyboard-"); } imicon = LoadImageWithText( classicui, sc, path, iconText, cairo_image_surface_get_width(activeIcon->image), cairo_image_surface_get_height(activeIcon->image), true); } if (imicon == NULL) imicon = LoadImage(sc, path, flag); fcitx_utils_free(tmpstr); if (imicon == NULL) { imicon = LoadImage(sc, fallbackIcon, fallbackToDefault); } else { SkinImage* activeIcon = LoadImage(sc, fallbackIcon, fallbackToDefault); if (activeIcon) { ResizeSurface(&imicon->image, cairo_image_surface_get_width(activeIcon->image), cairo_image_surface_get_height(activeIcon->image)); } } return imicon; }
char* FcitxNotificationItemGetIconNameString(FcitxNotificationItem* notificationitem) { char* iconName = NULL; FcitxIM* im = FcitxInstanceGetCurrentIM(notificationitem->owner); const char* icon = ""; if (im) { if (strncmp(im->uniqueName, "fcitx-keyboard-", strlen("fcitx-keyboard-")) != 0) { icon = im->strIconName; } else { return strdup("input-keyboard"); } } boolean result = CheckAddPrefix(&icon); fcitx_utils_alloc_cat_str(iconName, result ? "fcitx-" : "", icon); return iconName; }
char* FcitxNotificationItemGetIconNameString(FcitxNotificationItem* notificationitem) { char* iconName = NULL; FcitxIM* im = FcitxInstanceGetCurrentIM(notificationitem->owner); const char* icon = ""; if (im) { if (strncmp(im->uniqueName, "fcitx-keyboard-", strlen("fcitx-keyboard-")) != 0) { icon = im->strIconName; } else { return strdup("input-keyboard"); } } fcitx_utils_alloc_cat_str(iconName, (icon[0] == '\0' || icon[0] == '/') ? "" : "fcitx-", icon); return iconName; }
const char* FcitxNotificationItemGetLabel(FcitxNotificationItem* notificationitem) { const char* label = ""; FcitxInputContext* ic = FcitxInstanceGetCurrentIC(notificationitem->owner); if (ic) { FcitxIM* im = FcitxInstanceGetCurrentIM(notificationitem->owner); if (im) { if (strncmp(im->uniqueName, "fcitx-keyboard-", strlen("fcitx-keyboard-")) == 0) { strncpy(notificationitem->layoutNameBuffer, im->uniqueName + strlen("fcitx-keyboard-"), 2); notificationitem->layoutNameBuffer[2] = '\0'; label = notificationitem->layoutNameBuffer; } } } return label; }
INPUT_RETURN_VALUE CloudPinyinGetCandWord(void* arg, FcitxCandidateWord* candWord) { FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg; CloudCandWord* cloudCand = candWord->priv; FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); if (cloudCand->filled) { char *py; char *string = GetCurrentString(cloudpinyin, &py); if (py) { *py = 0; snprintf(FcitxInputStateGetOutputString(input), MAX_USER_INPUT, "%s%s", string, candWord->strWord); FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); if (im) { char *output_string = FcitxInputStateGetOutputString(input); FCITX_DEF_MODULE_ARGS(args, output_string); if (strcmp(im->uniqueName, "sunpinyin") == 0) { FcitxSunPinyinInvokeAddWord(cloudpinyin->owner, args); } else if (strcmp(im->uniqueName, "shuangpin") == 0 || strcmp(im->uniqueName, "pinyin") == 0) { FcitxPinyinInvokeAddUserPhrase(cloudpinyin->owner, args); } else if (strcmp(im->uniqueName, "pinyin-libpinyin") == 0 || strcmp(im->uniqueName, "shuangpin-libpinyin") == 0) { FcitxLibPinyinInvokeAddWord(cloudpinyin->owner, args); } else if (strcmp(im->uniqueName, "sogou-pinyin") == 0) { FcitxSogouPinyinInvokeAddWord(cloudpinyin->owner, args); } } } if (string) free(string); return IRV_COMMIT_STRING; } else { return IRV_DO_NOTHING; } }
FCITX_EXPORT_API void FcitxUICommitPreedit(FcitxInstance* instance) { if (!instance->CurrentIC) return; boolean callOnClose = false; boolean doServerSideCommit = false; if (!instance->config->bDontCommitPreeditWhenUnfocus && !(instance->CurrentIC->contextCaps & CAPACITY_CLIENT_UNFOCUS_COMMIT)) { callOnClose = true; doServerSideCommit = true; } if (instance->CurrentIC->contextCaps & CAPACITY_CLIENT_UNFOCUS_COMMIT) { callOnClose = true; } if (callOnClose) { FcitxIM* im = FcitxInstanceGetCurrentIM(instance); if (im && im->OnClose) { im->OnClose(im->klass, CET_LostFocus); } } if (doServerSideCommit) { FcitxInputState* input = FcitxInstanceGetInputState(instance); FcitxMessages* clientPreedit = FcitxInputStateGetClientPreedit(input); if (FcitxMessagesGetMessageCount(clientPreedit) > 0) { char* str = FcitxUIMessagesToCStringForCommit(clientPreedit); if (str[0]) { FcitxInstanceCommitString(instance, instance->CurrentIC, str); } free(str); } FcitxMessagesSetMessageCount(clientPreedit, 0); } }
SkinImage* GetIMIcon(FcitxInstance* instance, FcitxSkin *sc, const char* fallbackIcon, boolean imfallbackToDefault, boolean fallbackToDefault) { FcitxIM* im = FcitxInstanceGetCurrentIM(instance); char* path; if (im->strIconName[0] == '/') path = strdup(im->strIconName); else asprintf(&path, "%s.png", im->strIconName); SkinImage* imicon = LoadImage(sc, path, imfallbackToDefault); if (imicon == NULL) imicon = LoadImage(sc, fallbackIcon, fallbackToDefault); else { SkinImage* activeIcon = LoadImage(sc, fallbackIcon, fallbackToDefault); if (activeIcon) { ResizeSurface(&imicon->image, cairo_image_surface_get_width(activeIcon->image), cairo_image_surface_get_height(activeIcon->image)); } } free(path); return imicon; }
INPUT_RETURN_VALUE CloudPinyinToggle(void* arg) { FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg; FcitxInstance* instance = cloudpinyin->owner; FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); if (CHECK_VALID_IM) { cloudpinyin->config.bEnabled = !cloudpinyin->config.bEnabled; FcitxFreeDesktopNotifyShowAddonTip( instance, "fcitx-cloudpinyin-toggle", "fcitx", _("Cloud Pinyin"), cloudpinyin->config.bEnabled ? _("Cloud Pinyin is Enabled.") : _("Cloud Pinyin is Disabled.")); CloudPinyinConfigSave(&cloudpinyin->config); // TODO: add a notification here return IRV_DO_NOTHING; } return IRV_TO_PROCESS; }
void* LibpinyinSavePinyinWord(void* arg, FcitxModuleFunctionArg args) { #if 0 FcitxLibpinyinAddonInstance* libpinyinaddon = (FcitxLibpinyinAddonInstance*) arg; FcitxIM* im = FcitxInstanceGetCurrentIM(libpinyinaddon->owner); pinyin_context_t* context = NULL; if (strcmp(im->uniqueName, "pinyin-libpinyin") == 0 || strcmp(im->uniqueName, "shuangpin-libpinyin") == 0) { context = libpinyinaddon->pinyin_context; } if (!context) return NULL; FcitxLibpinyin* libpinyin = (FcitxLibpinyin*) im->klass; import_iterator_t* iter = pinyin_begin_add_phrases(context, 15); char* hz = (char*) args.args[0]; pinyin_iterator_add_phrase(iter, hz, libpinyin->inst->m_raw_full_pinyin, -1); pinyin_end_add_phrases(iter); #endif return NULL; }
static int check_im_type(PinyinEnhance *pyenhance) { FcitxIM *im = FcitxInstanceGetCurrentIM(pyenhance->owner); if (!im) return PY_IM_INVALID; if (strcmp(im->uniqueName, "pinyin") == 0 || strcmp(im->uniqueName, "pinyin-libpinyin") == 0 || strcmp(im->uniqueName, "googlepinyin") == 0 || strcmp(im->uniqueName, "shuangpin-libpinyin") == 0) return PY_IM_PINYIN; if (strcmp(im->uniqueName, "shuangpin") == 0) return PY_IM_SHUANGPIN; if (strcmp(im->uniqueName, "sunpinyin") == 0) { boolean sp = false; char *str; FCITX_DEF_MODULE_ARGS(args, "", &sp); str = FcitxSunPinyinInvokeGetFullPinyin(im->owner->owner, args); fcitx_utils_free(str); return sp ? PY_IM_SHUANGPIN : PY_IM_PINYIN; } return PY_IM_INVALID; }
INPUT_RETURN_VALUE CloudPinyinGetCandWord(void* arg, FcitxCandidateWord* candWord) { FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg; CloudCandWord* cloudCand = candWord->priv; FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); if (cloudCand->filled) { char* string = GetCurrentString(cloudpinyin); char* py = SplitHZAndPY(string); if (py) { *py = 0; snprintf(FcitxInputStateGetOutputString(input), MAX_USER_INPUT, "%s%s", string, candWord->strWord); FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); FcitxModuleFunctionArg args; args.args[0] = FcitxInputStateGetOutputString(input); if (im) { if (strcmp(im->uniqueName, "sunpinyin") == 0) { //InvokeModuleFunctionWithName(cloudpinyin->owner, "fcitx-sunpinyin", 1, args); } else if (strcmp(im->uniqueName, "shuangpin") == 0 || strcmp(im->uniqueName, "pinyin") == 0) { FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-pinyin", 7, args); } } } if (string) free(string); return IRV_COMMIT_STRING; } else return IRV_DO_NOTHING; }
char *GetCurrentString(FcitxCloudPinyin* cloudpinyin, char **ascii_part) { FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); if (!im) { *ascii_part = NULL; return NULL; } FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); char* string = FcitxUIMessagesToCString(FcitxInputStateGetPreedit(input)); char p[MAX_USER_INPUT + 1], *pinyin, *lastpos; pinyin = fcitx_utils_get_ascii_part(string); lastpos = pinyin; boolean endflag; int hzlength = pinyin - string; size_t plength = hzlength; strncpy(p, string, hzlength); p[hzlength] = '\0'; // lastpos points to the start of a pinyin // pinyin points to the end of current pinyin // for example // xi'an // | | // l p // and we check the separator by supportSeparator for each engine. // shuangpin-libpinyin returns full pinyin in preedit, so we also treat space as separator. do { endflag = (*pinyin != '\0'); if (*pinyin == ' ' || *pinyin == '\'' || *pinyin == '\0') { boolean isSeparator = false; // skip all continous separator while (*pinyin == ' ' || *pinyin == '\'') { isSeparator = isSeparator || (*pinyin) == '\'' || (strcmp(im->uniqueName, "shuangpin-libpinyin") == 0 && (*pinyin) == ' '); *pinyin = 0; pinyin++; } if (*lastpos != '\0') { char* result = NULL; boolean isshuangpin = false; if (strcmp(im->uniqueName, "sunpinyin") == 0) { FCITX_DEF_MODULE_ARGS(args, lastpos, &isshuangpin); result = FcitxSunPinyinInvokeGetFullPinyin(cloudpinyin->owner, args); } else if (strcmp(im->uniqueName, "shuangpin") == 0) { isshuangpin = true; result = FcitxPinyinSP2QP(cloudpinyin->owner, lastpos); } if (isshuangpin) { if (result) { if (plength + strlen(result) + (engine[cloudpinyin->config.source].supportSeparator ? 1 : 0) < MAX_USER_INPUT) { strcat(p + plength, result); plength += strlen(result); if (engine[cloudpinyin->config.source].supportSeparator) { strcat(p + plength, "'"); plength += 1; } free(result); } else { p[hzlength] = '\0'; break; } } } else { #define PINYIN_USE_SEPARATOR_CASE (isSeparator && engine[cloudpinyin->config.source].supportSeparator) if (plength + strlen(lastpos) + (PINYIN_USE_SEPARATOR_CASE ? 1 : 0) < MAX_USER_INPUT) { strcat(p + plength, lastpos); plength += strlen(lastpos); if (PINYIN_USE_SEPARATOR_CASE) { strcat(p + plength, "'"); plength += 1; } } else { p[hzlength] = '\0'; break; } } isSeparator = false; } lastpos = pinyin; } else { pinyin ++; } } while(endflag); free(string); /* no pinyin append, return NULL for off it */ if (p[hzlength] == '\0') { *ascii_part = NULL; return NULL; } else { if (plength >= 1 && p[plength - 1] == '\'') { p[plength - 1] = '\0'; } char *res = strdup(p); *ascii_part = res + hzlength; return res; } }
void CloudPinyinHandleRequest(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue) { if (queue->type == RequestKey) { cloudpinyin->isrequestkey = false; if (queue->source != cloudpinyin->config.source) return; if (queue->http_code == 200) { if (engine[cloudpinyin->config.source].ParseKey) engine[cloudpinyin->config.source].ParseKey(cloudpinyin, queue); } } else if (queue->type == RequestPinyin) { if (queue->http_code == 200 && cloudpinyin->config.source == queue->source) { char *realstring = engine[cloudpinyin->config.source].ParsePinyin(cloudpinyin, queue); if (realstring) { CloudPinyinCache* cacheEntry = CloudPinyinCacheLookup(cloudpinyin, queue->pinyin); if (cacheEntry == NULL) cacheEntry = CloudPinyinAddToCache(cloudpinyin, queue->pinyin, realstring); FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); char* strToFree = NULL, *inputString; strToFree = GetCurrentString(cloudpinyin); inputString = SplitHZAndPY(strToFree); if (inputString) { FcitxLog(LOGLEVEL, "fill: %s %s", inputString, queue->pinyin); if (strcmp(inputString, queue->pinyin) == 0) { if (CHECK_VALID_IM) { CloudPinyinFillCandidateWord(cloudpinyin, inputString); } } } if (strToFree) free(strToFree); free(realstring); } } if (queue->http_code != 200) { cloudpinyin->errorcount ++; if (cloudpinyin->errorcount > MAX_ERROR) { cloudpinyin->initialized = false; cloudpinyin->key[0] = '\0'; cloudpinyin->errorcount = 0; } } } CloudPinyinReleaseCurlHandle(cloudpinyin, queue->curl); if (queue->str) free(queue->str); if (queue->pinyin) free(queue->pinyin); free(queue); }
char *GetCurrentString(FcitxCloudPinyin* cloudpinyin) { FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); if (!im) return NULL; FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); char* string = FcitxUIMessagesToCString(FcitxInputStateGetPreedit(input)); char p[MAX_USER_INPUT + 1], *pinyin, *lastpos; pinyin = SplitHZAndPY(string); lastpos = pinyin; boolean endflag; int hzlength = pinyin - string; size_t plength = hzlength; strncpy(p, string, hzlength); p[hzlength] = '\0'; do { endflag = (*pinyin != '\0'); if (*pinyin == ' ' || *pinyin == '\'' || *pinyin == '\0') { *pinyin = 0; if (*lastpos != '\0') { char* result = NULL; FcitxModuleFunctionArg arg; arg.args[0] = lastpos; boolean isshuangpin = false; if (strcmp(im->uniqueName, "sunpinyin") == 0) { boolean issp = false; arg.args[1] = &issp; result = FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-sunpinyin", 0, arg); isshuangpin = issp; } else if (strcmp(im->uniqueName, "shuangpin") == 0) { isshuangpin = true; result = InvokeFunction(cloudpinyin->owner, FCITX_PINYIN, SP2QP, arg); } if (isshuangpin) { if (result) { if (plength + strlen(result) < MAX_USER_INPUT) { strcat(p + plength, result); plength += strlen(result); free(result); } else { p[hzlength] = '\0'; break; } } } else { if (plength + strlen(lastpos) < MAX_USER_INPUT) { strcat(p + plength, lastpos); plength += strlen(lastpos); } else { p[hzlength] = '\0'; break; } } } lastpos = pinyin + 1; } pinyin ++; } while(endflag); free(string); /* no pinyin append, return NULL for off it */ if (p[hzlength] == '\0') return NULL; else return strdup(p); }
void FcitxDBusMenuDoEvent(void* arg) { FcitxNotificationItem* notificationitem = (FcitxNotificationItem*) arg; FcitxInstance* instance = notificationitem->owner; int32_t id = notificationitem->pendingActionId; notificationitem->pendingActionId = -1; int32_t menu = ACTION_MENU(id); int32_t index = ACTION_INDEX(id); if (index <= 0) return; if (menu == 0) { if (index <= 8 && index > 0) { switch(index) { case 1: { char* args[] = { "xdg-open", "http://fcitx-im.org/", 0 }; fcitx_utils_start_process(args); } break; case 4: { FcitxIM* im = FcitxInstanceGetCurrentIM(instance); if (im && im->owner) { fcitx_utils_launch_configure_tool_for_addon(im->uniqueName); } else { fcitx_utils_launch_configure_tool(); } } break; case 5: fcitx_utils_launch_configure_tool(); break; case 6: fcitx_utils_launch_restart(); break; case 7: FcitxInstanceEnd(instance); break; } } else { int index = STATUS_INDEX(id); const char* name = NULL; if (STATUS_ISCOMP(id)) { UT_array* uicompstats = FcitxInstanceGetUIComplexStats(instance); FcitxUIComplexStatus* compstatus = (FcitxUIComplexStatus*) utarray_eltptr(uicompstats, index); if (compstatus) { name = compstatus->name; } } else { UT_array* uistats = FcitxInstanceGetUIStats(instance); FcitxUIStatus* status = (FcitxUIStatus*) utarray_eltptr(uistats, index); if (status) { name = status->name; } } if (name) { FcitxUIUpdateStatus(instance, name); } } } else if (menu > 0) { UT_array* uimenus = FcitxInstanceGetUIMenus(instance); FcitxUIMenu** menup = (FcitxUIMenu**) utarray_eltptr(uimenus, menu - 1), *menu; if (!menup) return; menu = *menup; if (menu->MenuAction) { menu->MenuAction(menu, index - 1); } } }