Exemplo n.º 1
0
static void*
FcitxKkcCreate(FcitxInstance *instance)
{
    FcitxKkc *kkc = fcitx_utils_new(FcitxKkc);
    bindtextdomain("fcitx-kkc", LOCALEDIR);
    bind_textdomain_codeset("fcitx-kkc", "UTF-8");
    kkc->owner = instance;

    if (!KkcLoadConfig(&kkc->config)) {
        free(kkc);
        return NULL;
    }

#if !GLIB_CHECK_VERSION(2, 36, 0)
    g_type_init();
#endif
    kkc_init();

    KkcLanguageModel* model = kkc_language_model_load("sorted3", NULL);
    if (!model) {
        free(kkc);
        return NULL;
    }

    FcitxXDGMakeDirUser("kkc/rules");
    FcitxXDGMakeDirUser("kkc/dictionary");

    kkc->model = model;
    kkc->context = kkc_context_new(model);

    if (!FcitxKkcLoadDictionary(kkc) || !FcitxKkcLoadRule(kkc)) {
        g_object_unref(kkc->context);
        free(kkc);
        return NULL;
    }
    kkc_context_set_punctuation_style(kkc->context, KKC_PUNCTUATION_STYLE_JA_JA);
    kkc_context_set_input_mode(kkc->context, KKC_INPUT_MODE_HIRAGANA);
    kkc->tempMsg = FcitxMessagesNew();


    FcitxKkcApplyConfig(kkc);

    FcitxIMIFace iface;
    memset(&iface, 0, sizeof(FcitxIMIFace));
    iface.Init = FcitxKkcInit;
    iface.DoInput = FcitxKkcDoInput;
    iface.DoReleaseInput = FcitxKkcDoReleaseInput;
    iface.GetCandWords = FcitxKkcGetCandWords;
    iface.Save = FcitxKkcSave;
    iface.ResetIM = FcitxKkcResetIM;
    iface.OnClose = FcitxKkcOnClose;

    FcitxInstanceRegisterIMv2(instance, kkc, "kkc", _("Kana Kanji"), "kkc", iface, 1, "ja");


#define INIT_MENU(VARNAME, NAME, I18NNAME, STATUS_NAME, STATUS_ARRAY, SIZE) \
    do { \
        FcitxUIRegisterComplexStatus(instance, kkc, \
            STATUS_NAME, \
            I18NNAME, \
            I18NNAME, \
            NULL, \
            FcitxKkcGet##NAME##IconName \
        ); \
        FcitxMenuInit(&VARNAME); \
        VARNAME.name = strdup(I18NNAME); \
        VARNAME.candStatusBind = strdup(STATUS_NAME); \
        VARNAME.UpdateMenu = FcitxKkcUpdate##NAME##Menu; \
        VARNAME.MenuAction = FcitxKkc##NAME##MenuAction; \
        VARNAME.priv = kkc; \
        VARNAME.isSubMenu = false; \
        int i; \
        for (i = 0; i < SIZE; i ++) \
            FcitxMenuAddMenuItem(&VARNAME, _(STATUS_ARRAY[i].label), MENUTYPE_SIMPLE, NULL); \
        FcitxUIRegisterMenu(instance, &VARNAME); \
        FcitxUISetStatusVisable(instance, STATUS_NAME, false); \
    } while(0)

    INIT_MENU(kkc->inputModeMenu, InputMode, _("Input Mode"), "kkc-input-mode", input_mode_status, KKC_INPUT_MODE_DIRECT);

    kkc->handler = g_signal_connect(kkc->context, "notify::input-mode", G_CALLBACK(_kkc_input_mode_changed_cb), kkc);
    FcitxKkcUpdateInputMode(kkc);

    kkc_context_set_input_mode(kkc->context, kkc->config.initialInputMode);

    FcitxIMEventHook hk;
    hk.arg = kkc;
    hk.func = FcitxKkcResetHook;
    FcitxInstanceRegisterResetInputHook(instance, hk);

    FcitxKkcAddFunctions(instance);
    return kkc;
}
Exemplo n.º 2
0
static void language_model_tests_test_load (LanguageModelTests* self) {
	gchar* srcdir = NULL;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	GError * _inner_error_ = NULL;
#line 8 "/home/ueno/devel/libkkc/tests/language-model.vala"
	g_return_if_fail (self != NULL);
#line 86 "language-model.c"
	{
		KkcLanguageModel* _tmp0_ = NULL;
		KkcLanguageModel* _tmp1_ = NULL;
#line 10 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp0_ = kkc_language_model_load ("nonexistent", &_inner_error_);
#line 10 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp1_ = _tmp0_;
#line 10 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_object_unref0 (_tmp1_);
#line 10 "/home/ueno/devel/libkkc/tests/language-model.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 10 "/home/ueno/devel/libkkc/tests/language-model.vala"
			if (_inner_error_->domain == KKC_LANGUAGE_MODEL_ERROR) {
#line 100 "language-model.c"
				goto __catch0_kkc_language_model_error;
			}
			goto __finally0;
		}
#line 11 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_assert_not_reached ();
#line 107 "language-model.c"
	}
	goto __finally0;
	__catch0_kkc_language_model_error:
	{
		GError* e = NULL;
#line 9 "/home/ueno/devel/libkkc/tests/language-model.vala"
		e = _inner_error_;
#line 9 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_inner_error_ = NULL;
#line 9 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_error_free0 (e);
#line 119 "language-model.c"
	}
	__finally0:
#line 9 "/home/ueno/devel/libkkc/tests/language-model.vala"
	if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 9 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 9 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_clear_error (&_inner_error_);
#line 9 "/home/ueno/devel/libkkc/tests/language-model.vala"
		return;
#line 130 "language-model.c"
	}
	{
		KkcLanguageModel* _tmp2_ = NULL;
		KkcLanguageModel* _tmp3_ = NULL;
#line 16 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp2_ = kkc_language_model_load ("text3", &_inner_error_);
#line 16 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp3_ = _tmp2_;
#line 16 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_object_unref0 (_tmp3_);
#line 16 "/home/ueno/devel/libkkc/tests/language-model.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 16 "/home/ueno/devel/libkkc/tests/language-model.vala"
			if (_inner_error_->domain == KKC_LANGUAGE_MODEL_ERROR) {
#line 145 "language-model.c"
				goto __catch1_kkc_language_model_error;
			}
			goto __finally1;
		}
	}
	goto __finally1;
	__catch1_kkc_language_model_error:
	{
		GError* e = NULL;
#line 15 "/home/ueno/devel/libkkc/tests/language-model.vala"
		e = _inner_error_;
#line 15 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_inner_error_ = NULL;
#line 18 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_assert_not_reached ();
#line 15 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_error_free0 (e);
#line 163 "language-model.c"
	}
	__finally1:
#line 15 "/home/ueno/devel/libkkc/tests/language-model.vala"
	if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 15 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 15 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_clear_error (&_inner_error_);
#line 15 "/home/ueno/devel/libkkc/tests/language-model.vala"
		return;
#line 174 "language-model.c"
	}
#line 21 "/home/ueno/devel/libkkc/tests/language-model.vala"
	_tmp4_ = g_getenv ("srcdir");
#line 21 "/home/ueno/devel/libkkc/tests/language-model.vala"
	_tmp5_ = g_strdup (_tmp4_);
#line 21 "/home/ueno/devel/libkkc/tests/language-model.vala"
	srcdir = _tmp5_;
#line 22 "/home/ueno/devel/libkkc/tests/language-model.vala"
	_tmp6_ = srcdir;
#line 22 "/home/ueno/devel/libkkc/tests/language-model.vala"
	_vala_assert (_tmp6_ != NULL, "srcdir != null");
#line 186 "language-model.c"
	{
		const gchar* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		KkcLanguageModelMetadata* _tmp10_ = NULL;
		KkcLanguageModelMetadata* _tmp11_ = NULL;
#line 25 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp7_ = srcdir;
#line 25 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp8_ = g_build_filename (_tmp7_, "language-model-metadata-bad1.json", NULL);
#line 25 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp9_ = _tmp8_;
#line 25 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp10_ = kkc_language_model_metadata_new ("bad1", _tmp9_, &_inner_error_);
#line 25 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp11_ = _tmp10_;
#line 25 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_object_unref0 (_tmp11_);
#line 25 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_free0 (_tmp9_);
#line 25 "/home/ueno/devel/libkkc/tests/language-model.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 209 "language-model.c"
			goto __catch2_g_error;
		}
#line 29 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_assert_not_reached ();
#line 214 "language-model.c"
	}
	goto __finally2;
	__catch2_g_error:
	{
		GError* e = NULL;
#line 24 "/home/ueno/devel/libkkc/tests/language-model.vala"
		e = _inner_error_;
#line 24 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_inner_error_ = NULL;
#line 24 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_error_free0 (e);
#line 226 "language-model.c"
	}
	__finally2:
#line 24 "/home/ueno/devel/libkkc/tests/language-model.vala"
	if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 24 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_free0 (srcdir);
#line 24 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 24 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_clear_error (&_inner_error_);
#line 24 "/home/ueno/devel/libkkc/tests/language-model.vala"
		return;
#line 239 "language-model.c"
	}
	{
		const gchar* _tmp12_ = NULL;
		gchar* _tmp13_ = NULL;
		gchar* _tmp14_ = NULL;
		KkcLanguageModelMetadata* _tmp15_ = NULL;
		KkcLanguageModelMetadata* _tmp16_ = NULL;
#line 34 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp12_ = srcdir;
#line 34 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp13_ = g_build_filename (_tmp12_, "language-model-metadata-bad2.json", NULL);
#line 34 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp14_ = _tmp13_;
#line 34 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp15_ = kkc_language_model_metadata_new ("bad2", _tmp14_, &_inner_error_);
#line 34 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_tmp16_ = _tmp15_;
#line 34 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_object_unref0 (_tmp16_);
#line 34 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_free0 (_tmp14_);
#line 34 "/home/ueno/devel/libkkc/tests/language-model.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 263 "language-model.c"
			goto __catch3_g_error;
		}
#line 38 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_assert_not_reached ();
#line 268 "language-model.c"
	}
	goto __finally3;
	__catch3_g_error:
	{
		GError* e = NULL;
#line 33 "/home/ueno/devel/libkkc/tests/language-model.vala"
		e = _inner_error_;
#line 33 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_inner_error_ = NULL;
#line 33 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_error_free0 (e);
#line 280 "language-model.c"
	}
	__finally3:
#line 33 "/home/ueno/devel/libkkc/tests/language-model.vala"
	if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 33 "/home/ueno/devel/libkkc/tests/language-model.vala"
		_g_free0 (srcdir);
#line 33 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 33 "/home/ueno/devel/libkkc/tests/language-model.vala"
		g_clear_error (&_inner_error_);
#line 33 "/home/ueno/devel/libkkc/tests/language-model.vala"
		return;
#line 293 "language-model.c"
	}
#line 8 "/home/ueno/devel/libkkc/tests/language-model.vala"
	_g_free0 (srcdir);
#line 297 "language-model.c"
}