Пример #1
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;
}
Пример #2
0
static int
fxaddon_scan_addon(FILE *ifp, FILE *ofp)
{
    FcitxDesktopFile dfile;
    char *buff = NULL;
    unsigned int i;
    char **p;
    if (!fcitx_desktop_file_init(&dfile, NULL, NULL))
        return 1;
    if (!fcitx_desktop_file_load_fp(&dfile, ifp))
        return 1;
    fclose(ifp);
    FcitxDesktopGroup *addon_grp;
    FcitxDesktopEntry *tmp_ety;
    addon_grp = fcitx_desktop_file_find_group(&dfile, "FcitxAddon");
    if (!addon_grp)
        return 1;
    tmp_ety = fcitx_desktop_group_find_entry(addon_grp, "Name");
    if (!tmp_ety)
        return 1;
    const char *name = tmp_ety->value;
    tmp_ety = fcitx_desktop_group_find_entry(addon_grp, "Prefix");
    if (!tmp_ety)
        return 1;
    const char *prefix = tmp_ety->value;
    UT_array macros;
    fxaddon_load_numbered_entries(&macros, addon_grp, "Macro", false);
    UT_array includes;
    fxaddon_load_numbered_entries(&includes, addon_grp, "Include", false);
    UT_array functions;
    fxaddon_load_numbered_entries(&functions, addon_grp, "Function", true);
    fxaddon_write_copyright(ofp);
    size_t name_len = strlen(name);
    buff = fcitx_utils_set_str_with_len(buff, name, name_len);
    fxaddon_name_to_macro(buff);
    _write_str(ofp, "\n#ifndef __FCITX_MODULE_");
    _write_len(ofp, buff, name_len);
    _write_str(ofp, "_H\n");
    _write_str(ofp, "#define __FCITX_MODULE_");
    _write_len(ofp, buff, name_len);
    _write_str(ofp, "_H\n"
                    "\n"
                    "#ifdef __cplusplus\n"
                    "extern \"C\" {\n"
                    "#endif\n"
                    "\n");
    for (i = 0;i < utarray_len(&macros);i++) {
        p = (char**)_utarray_eltptr(&macros, i);
        fxaddon_write_macro(ofp, &dfile, *p);
    }
    fxaddon_write_includes(ofp, &includes);
    utarray_done(&includes);
    _write_str(ofp, "DEFINE_GET_ADDON(\"");
    _write_len(ofp, name, name_len);
    _write_str(ofp, "\", ");
    _write_str(ofp, prefix);
    _write_str(ofp, ")\n\n");
    for (i = 0;i < utarray_len(&functions);i++) {
        p = (char**)_utarray_eltptr(&functions, i);
        fxaddon_write_function(ofp, &dfile, prefix, *p, i);
    }
    _write_str(ofp, "\n"
                    "#ifdef __cplusplus\n"
                    "}\n"
                    "#endif\n"
                    "\n"
                    "#endif\n");
    fclose(ofp);
    fcitx_utils_free(buff);
    fcitx_desktop_file_done(&dfile);
    utarray_done(&functions);
    return 0;
}