static void dialog_response (GtkWidget *widget, gint response_id, gpointer data) { switch (response_id) { case GTK_RESPONSE_OK: store_values (); pcvals.run = TRUE; gtk_widget_destroy (widget); break; default: gtk_widget_destroy (widget); break; } }
static void save_preset (void) { const gchar *preset_name; gchar *fname, *presets_dir_path; FILE *f; GList *thispath; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar vbuf[6][G_ASCII_DTOSTR_BUF_SIZE]; guchar color[3]; gint i; gchar *desc_escaped, *preset_name_escaped; preset_name = gtk_entry_get_text (GTK_ENTRY (presetnameentry)); thispath = parsepath (); store_values (); if (!thispath) { g_printerr ("Internal error: (save_preset) thispath == NULL\n"); return; } /* Create the ~/.gimp-$VER/gimpressionist/Presets directory if * it doesn't already exists. * */ presets_dir_path = g_build_filename ((const gchar *) thispath->data, "Presets", NULL); if (! g_file_test (presets_dir_path, G_FILE_TEST_IS_DIR)) { if (g_mkdir (presets_dir_path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1) { g_printerr ("Error creating folder \"%s\"!\n", gimp_filename_to_utf8 (presets_dir_path)); g_free (presets_dir_path); return; } } /* Check if the user-friendly name has changed. If so, then save it * under a new file. If not - use the same file name. */ if (selected_preset_orig_name && strcmp (preset_name, selected_preset_orig_name) == 0) { fname = g_build_filename (presets_dir_path, selected_preset_filename, NULL); } else { fname = preset_create_filename (preset_name, presets_dir_path); } g_free (presets_dir_path); if (!fname) { g_printerr ("Error building a filename for preset \"%s\"!\n", preset_name); return; } f = g_fopen (fname, "wt"); if (!f) { g_printerr ("Error opening file \"%s\" for writing!\n", gimp_filename_to_utf8 (fname)); g_free (fname); return; } fprintf (f, "%s\n", PRESETMAGIC); desc_escaped = g_strescape (presetdesc, NULL); fprintf (f, "desc=%s\n", desc_escaped); g_free (desc_escaped); preset_name_escaped = g_strescape (preset_name, NULL); fprintf (f, "name=%s\n", preset_name_escaped); g_free (preset_name_escaped); fprintf (f, "orientnum=%d\n", pcvals.orient_num); fprintf (f, "orientfirst=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.orient_first)); fprintf (f, "orientlast=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.orient_last)); fprintf (f, "orienttype=%d\n", pcvals.orient_type); fprintf (f, "sizenum=%d\n", pcvals.size_num); fprintf (f, "sizefirst=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.size_first)); fprintf (f, "sizelast=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.size_last)); fprintf (f, "sizetype=%d\n", pcvals.size_type); fprintf (f, "brushrelief=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.brush_relief)); fprintf (f, "brushdensity=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.brush_density)); fprintf (f, "brushgamma=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.brushgamma)); fprintf (f, "brushaspect=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.brush_aspect)); fprintf (f, "generalbgtype=%d\n", pcvals.general_background_type); fprintf (f, "generaldarkedge=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.general_dark_edge)); fprintf (f, "generalpaintedges=%d\n", pcvals.general_paint_edges); fprintf (f, "generaltileable=%d\n", pcvals.general_tileable); fprintf (f, "generaldropshadow=%d\n", pcvals.general_drop_shadow); fprintf (f, "generalshadowdarkness=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.general_shadow_darkness)); fprintf (f, "generalshadowdepth=%d\n", pcvals.general_shadow_depth); fprintf (f, "generalshadowblur=%d\n", pcvals.general_shadow_blur); fprintf (f, "devthresh=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.devthresh)); fprintf (f, "paperrelief=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.paper_relief)); fprintf (f, "paperscale=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.paper_scale)); fprintf (f, "paperinvert=%d\n", pcvals.paper_invert); fprintf (f, "paperoverlay=%d\n", pcvals.paper_overlay); fprintf (f, "selectedbrush=%s\n", pcvals.selected_brush); fprintf (f, "selectedpaper=%s\n", pcvals.selected_paper); gimp_rgb_get_uchar (&pcvals.color, &color[0], &color[1], &color[2]); fprintf (f, "color=%02x%02x%02x\n", color[0], color[1], color[2]); fprintf (f, "placetype=%d\n", pcvals.place_type); fprintf (f, "placecenter=%d\n", pcvals.placement_center); fprintf (f, "numorientvector=%d\n", pcvals.num_orient_vectors); for (i = 0; i < pcvals.num_orient_vectors; i++) { g_ascii_formatd (vbuf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.orient_vectors[i].x); g_ascii_formatd (vbuf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.orient_vectors[i].y); g_ascii_formatd (vbuf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.orient_vectors[i].dir); g_ascii_formatd (vbuf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.orient_vectors[i].dx); g_ascii_formatd (vbuf[4], G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.orient_vectors[i].dy); g_ascii_formatd (vbuf[5], G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.orient_vectors[i].str); fprintf (f, "orientvector=%d,%s,%s,%s,%s,%s,%s,%d\n", i, vbuf[0], vbuf[1], vbuf[2], vbuf[3], vbuf[4], vbuf[5], pcvals.orient_vectors[i].type); } fprintf (f, "orientangoff=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.orient_angle_offset)); fprintf (f, "orientstrexp=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.orient_strength_exponent)); fprintf (f, "orientvoronoi=%d\n", pcvals.orient_voronoi); fprintf (f, "numsizevector=%d\n", pcvals.num_size_vectors); for (i = 0; i < pcvals.num_size_vectors; i++) { g_ascii_formatd (vbuf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.size_vectors[i].x); g_ascii_formatd (vbuf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.size_vectors[i].y); g_ascii_formatd (vbuf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.size_vectors[i].siz); g_ascii_formatd (vbuf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.size_vectors[i].str); fprintf (f, "sizevector=%d,%s,%s,%s,%s\n", i, vbuf[0], vbuf[1], vbuf[2], vbuf[3]); } fprintf (f, "sizestrexp=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.size_strength_exponent)); fprintf (f, "sizevoronoi=%d\n", pcvals.size_voronoi); fprintf (f, "colortype=%d\n", pcvals.color_type); fprintf (f, "colornoise=%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.color_noise)); fclose (f); preset_refresh_presets (); reselect (presetlist, fname); g_free (fname); }