Beispiel #1
0
void test_string_map()
{
    FcitxStringMap* map = fcitx_string_map_new("a:true,b:false", ',');
    assert(fcitx_string_map_get(map, "a", false));
    assert(!fcitx_string_map_get(map, "b", false));
    assert(fcitx_string_map_get(map, "c", true));
    fcitx_string_map_set(map, "c", false);
    assert(!fcitx_string_map_get(map, "c", true));
    char* joined = fcitx_string_map_to_string(map, '\n');
    assert(strcmp(joined, "a:true\nb:false\nc:false") == 0);
    free(joined);

    fcitx_string_map_free(map);
}
Beispiel #2
0
static void*
FcitxNotifyCreate(FcitxInstance *instance)
{
    FcitxNotify *notify = fcitx_utils_new(FcitxNotify);
    notify->owner = instance;
    notify->notify_counter = 1;
    notify->conn = FcitxDBusGetConnection(notify->owner);
    if (fcitx_unlikely(!notify->conn))
        goto connect_error;

    DBusError err;
    dbus_error_init(&err);

    dbus_bus_add_match(notify->conn, NOTIFICATIONS_MATCH_ACTION, &err);
    if (fcitx_unlikely(dbus_error_is_set(&err)))
        goto filter_error;

    dbus_bus_add_match(notify->conn, NOTIFICATIONS_MATCH_CLOSED, &err);
    if (fcitx_unlikely(dbus_error_is_set(&err)))
        goto filter_error;

    if (fcitx_unlikely(!dbus_connection_add_filter(notify->conn,
                                                   FcitxNotifyDBusFilter,
                                                   notify, NULL)))
        goto filter_error;
    dbus_error_free(&err);

    notify->hide_notify = fcitx_string_map_new(NULL, '\0');
    fcitx_desktop_file_init(&notify->dconfig, NULL, NULL);
    FcitxNotifyLoadDConfig(notify);

    FcitxDBusWatchName(instance, NOTIFICATIONS_SERVICE_NAME, notify, FcitxNotifyOwnerChanged, NULL, NULL);
    FcitxNotifyGetCapabilities(notify);
    FcitxFreeDesktopNotifyAddFunctions(instance);

    return notify;
filter_error:
    dbus_bus_remove_match(notify->conn, NOTIFICATIONS_MATCH_ACTION, NULL);
    dbus_bus_remove_match(notify->conn, NOTIFICATIONS_MATCH_CLOSED, NULL);
    dbus_error_free(&err);
connect_error:
    free(notify);
    return NULL;
}
Beispiel #3
0
void* ChttransCreate(FcitxInstance* instance)
{
    FcitxChttrans* transState = fcitx_utils_malloc0(sizeof(FcitxChttrans));
    FcitxAddon* transAddon = FcitxAddonsGetAddonByName(FcitxInstanceGetAddons(instance), FCITX_CHTTRANS_NAME);
    transState->owner = instance;
    transState->enableIM = fcitx_string_map_new(NULL, '\0');
    if (!LoadChttransConfig(transState)) {
        fcitx_string_map_free(transState->enableIM);
        free(transState);
        return NULL;
    }

    FcitxHotkeyHook hk;
    hk.arg = transState;
    hk.hotkey = transState->hkToggle;
    hk.hotkeyhandle = HotkeyToggleChttransState;

    FcitxStringFilterHook shk;
    shk.arg = transState;
    shk.func = ChttransOutputFilter;

    FcitxIMEventHook imhk;
    imhk.arg = transState;
    imhk.func = ChttransIMChanged;

    FcitxInstanceRegisterHotkeyFilter(instance, hk);
    FcitxInstanceRegisterOutputFilter(instance, shk);
    FcitxInstanceRegisterCommitFilter(instance, shk);
    FcitxInstanceRegisterIMChangedHook(instance, imhk);
    FcitxUIRegisterStatus(instance, transState, "chttrans",
                          ChttransEnabled(transState) ? _("Convert to Traditional Chinese") :  _("Convert to Simplified Chinese"),
                          _("Toggle Simp/Trad Chinese Conversion"),
                          ToggleChttransState,
                          GetChttransEnabled);

    FcitxInstanceWatchContext(instance, CONTEXT_IM_LANGUAGE, ChttransLanguageChanged, transState);

    FcitxModuleAddFunction(transAddon, ChttransS2T);
    FcitxModuleAddFunction(transAddon, ChttransT2S);

    return transState;
}