fixed some issues (mainly coding style) with the new load and save

2003-02-02  Sven Neumann  <sven@gimp.org>

	* plug-ins/ifscompose/ifscompose.c: fixed some issues (mainly
	coding style) with the new load and save routines.
This commit is contained in:
Sven Neumann 2003-02-02 18:38:20 +00:00 committed by Sven Neumann
parent 76e8bf6a6a
commit 0b90802f3b
3 changed files with 143 additions and 105 deletions

View File

@ -1,3 +1,8 @@
2003-02-02 Sven Neumann <sven@gimp.org>
* plug-ins/ifscompose/ifscompose.c: fixed some issues (mainly
coding style) with the new load and save routines.
2003-02-02 Sven Neumann <sven@gimp.org> 2003-02-02 Sven Neumann <sven@gimp.org>
* plug-ins/ifscompose/ifscompose.c: applied a large patch from * plug-ins/ifscompose/ifscompose.c: applied a large patch from

4
NEWS
View File

@ -14,6 +14,8 @@ Overview of Changes in GIMP 1.3.12
- Lots of text tool changes [Sven] - Lots of text tool changes [Sven]
- Factored common code out of a number of plug-ins [Maurits] - Factored common code out of a number of plug-ins [Maurits]
- Cleaned up and improved the code that handles the plug-ins [Mitch] - Cleaned up and improved the code that handles the plug-ins [Mitch]
- Finished colorblindness display filter using the algorithm contributed
by Alex Wade and Robert Dougherty.
- Updated the gimprc man-page, or actually, wrote a tool that does it [Sven] - Updated the gimprc man-page, or actually, wrote a tool that does it [Sven]
- Improved the code that handles all the menus [Mitch] - Improved the code that handles all the menus [Mitch]
- Added new PSD save plug-in [Bolsh] - Added new PSD save plug-in [Bolsh]
@ -28,7 +30,7 @@ Overview of Changes in GIMP 1.3.12
Other contributors: Other contributors:
Garry R. Osgood, Jakub Steiner, Simon Budig, Henrik Brix Andersen, Garry R. Osgood, Jakub Steiner, Simon Budig, Henrik Brix Andersen,
Akkana, Carol Spears, Seth Burgess, Nathan Summers Akkana, Carol Spears, Seth Burgess, Nathan Summers, David Necas
Overview of Changes in GIMP 1.3.11 Overview of Changes in GIMP 1.3.11

View File

@ -288,7 +288,6 @@ static void ifs_compose_load_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void ifs_compose_save_callback (GtkWidget *widget, static void ifs_compose_save_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void ifs_compose_ok_callback (GtkWidget *widget, static void ifs_compose_ok_callback (GtkWidget *widget,
GtkWidget *window); GtkWidget *window);
@ -310,7 +309,6 @@ static gint undo_cur = -1;
static gint undo_num = 0; static gint undo_num = 0;
static gint undo_start = 0; static gint undo_start = 0;
static gchar ifsfile_path[PATH_MAX] = { '\0' };
/* num_elements = 0, signals not inited */ /* num_elements = 0, signals not inited */
static IfsComposeVals ifsvals = static IfsComposeVals ifsvals =
@ -2550,7 +2548,8 @@ ifs_compose_set_defaults (void)
gimp_palette_get_foreground (&color); gimp_palette_get_foreground (&color);
ifsvals.aspect_ratio = (gdouble)ifsD->drawable_height / ifsD->drawable_width; ifsvals.aspect_ratio =
(gdouble)ifsD->drawable_height / ifsD->drawable_width;
for (i = 0; i < ifsvals.num_elements; i++) for (i = 0; i < ifsvals.num_elements; i++)
aff_element_free (elements[i]); aff_element_free (elements[i]);
@ -2622,16 +2621,20 @@ ifs_compose_defaults_callback (GtkWidget *widget,
} }
/* show a transient message dialog */ /* show a transient message dialog */
void static void
ifscompose_message_dialog (GtkMessageType type, GtkWindow *parent, ifscompose_message_dialog (GtkMessageType type,
gchar *title, gchar *message) GtkWindow *parent,
const gchar *title,
const gchar *message)
{ {
GtkWidget *dlg; GtkWidget *dlg;
dlg = gtk_message_dialog_new (parent, 0, type, GTK_BUTTONS_OK, "%s", message); dlg = gtk_message_dialog_new (parent, 0, type, GTK_BUTTONS_OK, message);
gtk_window_set_transient_for (GTK_WINDOW (dlg), parent); gtk_window_set_transient_for (GTK_WINDOW (dlg), parent);
if (title) if (title)
gtk_window_set_title (GTK_WINDOW (dlg), title); gtk_window_set_title (GTK_WINDOW (dlg), title);
gtk_window_set_wmclass (GTK_WINDOW (dlg), "message", "Gimp"); gtk_window_set_wmclass (GTK_WINDOW (dlg), "message", "Gimp");
gtk_dialog_run (GTK_DIALOG (dlg)); gtk_dialog_run (GTK_DIALOG (dlg));
gtk_widget_destroy (dlg); gtk_widget_destroy (dlg);
@ -2639,24 +2642,29 @@ ifscompose_message_dialog (GtkMessageType type, GtkWindow *parent,
/* save an ifs file */ /* save an ifs file */
static void static void
ifsfile_save (GtkWidget *widget, GtkWidget *file_select) ifsfile_save (GtkWidget *widget,
GtkWidget *file_select)
{ {
gchar *str = ifsvals_stringify (&ifsvals, elements); const gchar *filename;
gchar *str;
FILE *fh; FILE *fh;
g_strlcpy (ifsfile_path, filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_select));
gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_select)),
PATH_MAX); str = ifsvals_stringify (&ifsvals, elements);
fh = fopen(ifsfile_path, "w");
if (fh) { fh = fopen (filename, "w");
fputs(str, fh); if (fh)
fclose(fh); {
gtk_widget_destroy (file_select); fputs (str, fh);
fclose (fh);
gtk_widget_hide (file_select);
} }
else { else
gchar *message = g_strdup_printf (_("Cannot save into file `%s'.\n" {
"Check the path and permissions.\n"), gchar *message = g_strdup_printf (_("Cannot save file '%s'.\n"
ifsfile_path); "Check the path and permissions."),
filename);
ifscompose_message_dialog (GTK_MESSAGE_ERROR, GTK_WINDOW (file_select), ifscompose_message_dialog (GTK_MESSAGE_ERROR, GTK_WINDOW (file_select),
"Save failed", message); "Save failed", message);
g_free (message); g_free (message);
@ -2679,7 +2687,8 @@ ifsfile_replace_ifsvals (IfsComposeVals *new_ifsvals,
ifsvals = *new_ifsvals; ifsvals = *new_ifsvals;
elements = new_elements; elements = new_elements;
for (i = 0; i < ifsvals.num_elements; i++) { for (i = 0; i < ifsvals.num_elements; i++)
{
aff_element_compute_trans (elements[i], width, height, aff_element_compute_trans (elements[i], width, height,
ifsvals.center_x, ifsvals.center_y); ifsvals.center_x, ifsvals.center_y);
aff_element_compute_color_trans (elements[i]); aff_element_compute_color_trans (elements[i]);
@ -2690,7 +2699,8 @@ ifsfile_replace_ifsvals (IfsComposeVals *new_ifsvals,
for (i = 0; i < ifsvals.num_elements; i++) for (i = 0; i < ifsvals.num_elements; i++)
element_selected[i] = FALSE; element_selected[i] = FALSE;
if (ifsOptD) { if (ifsOptD)
{
value_pair_update (ifsOptD->iterations_pair); value_pair_update (ifsOptD->iterations_pair);
value_pair_update (ifsOptD->subdivide_pair); value_pair_update (ifsOptD->subdivide_pair);
value_pair_update (ifsOptD->radius_pair); value_pair_update (ifsOptD->radius_pair);
@ -2709,18 +2719,21 @@ ifsfile_replace_ifsvals (IfsComposeVals *new_ifsvals,
/* load an ifs file */ /* load an ifs file */
static void static void
ifsfile_load (GtkWidget *widget, GtkWidget *file_select) ifsfile_load (GtkWidget *widget,
GtkWidget *file_select)
{ {
const gchar *filename;
gchar *buffer; gchar *buffer;
AffElement **new_elements; AffElement **new_elements;
IfsComposeVals new_ifsvals; IfsComposeVals new_ifsvals;
GError *error = NULL; GError *error = NULL;
g_strlcpy (ifsfile_path, filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_select));
gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_select)),
PATH_MAX); if (g_file_get_contents (filename, &buffer, NULL, &error))
if (g_file_get_contents (ifsfile_path, &buffer, NULL, &error)) { {
if (ifsvals_parse_string (buffer, &new_ifsvals, &new_elements)) { if (ifsvals_parse_string (buffer, &new_ifsvals, &new_elements))
{
guint i; guint i;
undo_begin (); undo_begin ();
@ -2732,62 +2745,79 @@ ifsfile_load (GtkWidget *widget, GtkWidget *file_select)
if (ifsD->auto_preview) if (ifsD->auto_preview)
ifs_compose_preview (); ifs_compose_preview ();
gtk_widget_destroy (file_select); gtk_widget_hide (file_select);
design_area_redraw (); design_area_redraw ();
} }
else { else
gchar *message = g_strdup_printf (_("File `%s' doesn't seem to be " {
"an IFS Compose file.\n"), gchar *message = g_strdup_printf (_("File '%s' doesn't seem to be "
ifsfile_path); "an IFS Compose file."),
ifscompose_message_dialog (GTK_MESSAGE_ERROR, GTK_WINDOW (file_select), filename);
ifscompose_message_dialog (GTK_MESSAGE_ERROR,
GTK_WINDOW (file_select),
_("Load failed"), message); _("Load failed"), message);
g_free (message); g_free (message);
} }
g_free (buffer); g_free (buffer);
} }
else { else
gchar *message = g_strdup_printf("%s.\n", error->message); {
ifscompose_message_dialog (GTK_MESSAGE_ERROR, GTK_WINDOW (file_select), ifscompose_message_dialog (GTK_MESSAGE_ERROR,
GTK_WINDOW (file_select),
_("Load failed"), error->message); _("Load failed"), error->message);
g_error_free (error); g_error_free (error);
g_free (message);
} }
} }
static void static void
ifs_compose_save_callback (GtkWidget *widget, gpointer data) ifs_compose_save_callback (GtkWidget *widget,
gpointer data)
{ {
GtkWidget *file_select; static GtkWidget *file_select = NULL;
if (!file_select)
{
file_select = gtk_file_selection_new (_("Save as IFS file")); file_select = gtk_file_selection_new (_("Save as IFS file"));
gimp_help_connect (file_select, gimp_standard_help_func, gimp_help_connect (file_select, gimp_standard_help_func,
"filters/ifscompose.html"); "filters/ifscompose.html");
gtk_file_selection_set_filename (GTK_FILE_SELECTION (file_select),
ifsfile_path); g_signal_connect (GTK_FILE_SELECTION (file_select)->ok_button, "clicked",
g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (file_select)->ok_button), G_CALLBACK (ifsfile_save),
"clicked", G_CALLBACK (ifsfile_save), file_select);
g_signal_connect_swapped (G_OBJECT (GTK_FILE_SELECTION (file_select)->cancel_button),
"clicked", G_CALLBACK (gtk_widget_destroy),
file_select); file_select);
gtk_widget_show (file_select); g_signal_connect_swapped (GTK_FILE_SELECTION (file_select)->cancel_button,
"clicked",
G_CALLBACK (gtk_widget_destroy),
file_select);
}
gtk_window_present (GTK_WINDOW (file_select));
} }
static void static void
ifs_compose_load_callback (GtkWidget *widget, gpointer data) ifs_compose_load_callback (GtkWidget *widget,
gpointer data)
{ {
GtkWidget *file_select; static GtkWidget *file_select = NULL;
if (!file_select)
{
file_select = gtk_file_selection_new (_("Load IFS file")); file_select = gtk_file_selection_new (_("Load IFS file"));
gimp_help_connect (file_select, gimp_standard_help_func, gimp_help_connect (file_select, gimp_standard_help_func,
"filters/ifscompose.html"); "filters/ifscompose.html");
gtk_file_selection_set_filename (GTK_FILE_SELECTION (file_select),
ifsfile_path); g_signal_connect (GTK_FILE_SELECTION (file_select)->ok_button, "clicked",
g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (file_select)->ok_button), G_CALLBACK (ifsfile_load),
"clicked", G_CALLBACK (ifsfile_load), file_select);
g_signal_connect_swapped (G_OBJECT (GTK_FILE_SELECTION (file_select)->cancel_button),
"clicked", G_CALLBACK (gtk_widget_destroy),
file_select); file_select);
gtk_widget_show (file_select); g_signal_connect_swapped (GTK_FILE_SELECTION (file_select)->cancel_button,
"clicked",
G_CALLBACK (gtk_widget_hide),
file_select);
}
gtk_window_present (GTK_WINDOW (file_select));
} }
static void static void
@ -2939,8 +2969,9 @@ ifs_compose_preview (void)
if (ifsD->preview_iterations == 0) if (ifsD->preview_iterations == 0)
g_idle_add (preview_idle_render, NULL); g_idle_add (preview_idle_render, NULL);
ifsD->preview_iterations = ifsvals.iterations*((gdouble)width*height/ ifsD->preview_iterations =
(ifsD->drawable_width*ifsD->drawable_height)); ifsvals.iterations * ((gdouble) width * height /
(ifsD->drawable_width * ifsD->drawable_height));
} }
static void static void