Esempio n. 1
0
FCITX_EXPORT_API
void fcitx_color_to_string(const FcitxColor* color, char* str)
{
    str[0] = '#';
    str++;
    int v[4];
    v[0] = (int)(color->red * 255);
    v[1] = (int)(color->green * 255);
    v[2] = (int)(color->blue * 255);
    v[3] = (int)(color->alpha * 255);
    for (size_t i = 0; i < 4; i ++) {
        int value = RoundColor(v[i]);
        int hi = value / 16;
        int lo = value % 16;
        *str = to_hex_char(hi);
        str++;
        *str = to_hex_char(lo);
        str++;
    }

    *str = '\0';
}
void sync_filter(FcitxGenericConfig* gconfig, FcitxConfigGroup *group, FcitxConfigOption *option, void *value, FcitxConfigSync sync, void *arg)
{
    FcitxConfigOptionDesc *codesc = option->optionDesc;
    if (!codesc)
        return;
    if (sync == Raw2Value) {
        switch (codesc->type) {
        case T_I18NString:
            break;
        case T_Integer: {
            int value = atoi(option->rawValue);
            gtk_spin_button_set_value(GTK_SPIN_BUTTON(arg), value);
        }
        break;
        case T_Color: {
            int r = 0, g = 0, b = 0;
            char scolor[9];
            sscanf(option->rawValue, "%d %d %d", &r, &g, &b);
            r = RoundColor(r);
            g = RoundColor(g);
            b = RoundColor(b);
            snprintf(scolor, 8 , "#%02X%02X%02X", r, g, b);
            GdkColor color;
            gdk_color_parse(scolor, &color);
            gtk_color_button_set_color(GTK_COLOR_BUTTON(arg), &color);
        }
        break;
        case T_Boolean: {
            gboolean bl;
            if (strcmp(option->rawValue, "True") == 0)
                bl = TRUE;
            else
                bl = FALSE;

            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(arg), bl);
        }
        break;
        case T_Font: {
            gtk_font_button_set_font_name(GTK_FONT_BUTTON(arg), option->rawValue);
        }
        break;
        case T_Enum: {
            FcitxConfigEnum* cenum = &codesc->configEnum;
            int index = 0, i;
            for (i = 0; i < cenum->enumCount; i++) {
                if (strcmp(cenum->enumDesc[i], option->rawValue) == 0) {
                    index = i;
                }
            }
            gtk_combo_box_set_active(GTK_COMBO_BOX(arg), index);
        }
        break;
        case T_Hotkey: {
            FcitxHotkey hotkey[2];
            int j;
            FcitxHotkeySetKey(option->rawValue, hotkey);
            GArray *array = (GArray*) arg;

            for (j = 0; j < 2; j ++) {
                GtkWidget *button = g_array_index(array, GtkWidget*, j);
                keygrab_button_set_key(KEYGRAB_BUTTON(button), hotkey[j].sym, hotkey[j].state);
                if (hotkey[j].desc)
                    free(hotkey[j].desc);
            }
        }
        break;
        case T_File:
        case T_Char:
        case T_String: {
            gtk_entry_set_text(GTK_ENTRY(arg), option->rawValue);
        }
        break;
        }
    } else {
        if (codesc->type != T_I18NString && option->rawValue) {