diff --git a/ChangeLog b/ChangeLog index 7c83962252..f218d241f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,35 @@ +2002-12-02 Michael Natterer + + * app/core/gimpdata.[ch]: use GError for reporting load/save + errors. Added gimp_data_error_quark() and a GimpDataError enum. + Made simple virtual functions out of save(), get_extension() + and duplicate() because they don't need to be signals. + + * app/core/gimpbrush.[ch] + * app/core/gimpbrushgenerated.[ch] + * app/core/gimpbrushpipe.[ch] + * app/core/gimpgradient.[ch] + * app/core/gimppalette.[ch] + * app/core/gimppattern.[ch]: changed accordingly. Set data->dirty + to FALSE in each _load() function. + + * app/core/gimpdatafactory.[ch]: report GError messages here. + Changed the ugly factory->path pointer location hack to + factory->path_property_name and get the path from + factory->gimp->config. Added gimp_data_factory_data_duplicate() + implementation which was already declared in the header. + + * app/core/gimp.c: pass the path property name to + gimp_data_factory_new(). + + * app/widgets/gimpdatafactoryview.c: removed the duplicate + implementation and call gimp_data_factory_data_duplicate(). + + * app/core/gimpgradient.[ch]: added gimp_gradient_save_as_pov(). + + * app/gui/gradients-commands.c: removed save_as_pov implementation + and call gimp_gradient_save_as_pov(). + 2002-12-01 Sven Neumann * app/config/gimpconfig-blurbs.h: small cleanup. diff --git a/app/actions/gradients-commands.c b/app/actions/gradients-commands.c index 4b371a6f2d..9eeadbffbb 100644 --- a/app/actions/gradients-commands.c +++ b/app/actions/gradients-commands.c @@ -150,75 +150,17 @@ static void gradients_save_as_pov_ok_callback (GtkWidget *widget, GimpGradient *gradient) { - GtkFileSelection *filesel; - const gchar *filename; - FILE *file; - GimpGradientSegment *seg; - gchar buf[3][G_ASCII_DTOSTR_BUF_SIZE]; + GtkFileSelection *filesel; + const gchar *filename; + GError *error = NULL; filesel = GTK_FILE_SELECTION (gtk_widget_get_toplevel (widget)); filename = gtk_file_selection_get_filename (filesel); - file = fopen (filename, "wb"); - - if (!file) + if (! gimp_gradient_save_as_pov (gradient, filename, &error)) { - g_message ("Could not open \"%s\"", filename); - } - else - { - fprintf (file, "/* color_map file created by the GIMP */\n"); - fprintf (file, "/* http://www.gimp.org/ */\n"); - - fprintf (file, "color_map {\n"); - - for (seg = gradient->segments; seg; seg = seg->next) - { - /* Left */ - g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->left_color.r); - g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->left_color.g); - g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->left_color.b); - g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", - 1.0 - seg->left_color.a); - - fprintf (file, "\t[%f color rgbt <%s, %s, %s, %s>]\n", - seg->left, - buf[0], buf[1], buf[2], buf[3]); - - /* Middle */ - g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", - (seg->left_color.r + seg->right_color.r) / 2.0); - g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", - (seg->left_color.g + seg->right_color.g) / 2.0); - g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", - (seg->left_color.b + seg->right_color.b) / 2.0); - g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", - 1.0 - (seg->left_color.a + seg->right_color.a) / 2.0); - - fprintf (file, "\t[%f color rgbt <%s, %s, %s, %s>]\n", - seg->middle, - buf[0], buf[1], buf[2], buf[3]); - - /* Right */ - g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->right_color.r); - g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->right_color.g); - g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->right_color.b); - g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", - 1.0 - seg->right_color.a); - - fprintf (file, "\t[%f color rgbt <%s, %s, %s, %s>]\n", - seg->right, - buf[0], buf[1], buf[2], buf[3]); - } - - fprintf (file, "} /* color_map */\n"); - fclose (file); + g_message (error->message); + g_clear_error (&error); } gtk_widget_destroy (GTK_WIDGET (filesel)); diff --git a/app/core/gimp.c b/app/core/gimp.c index 51a8206df6..d4ddd2331f 100644 --- a/app/core/gimp.c +++ b/app/core/gimp.c @@ -579,7 +579,7 @@ gimp_initialize (Gimp *gimp, gimp->brush_factory = gimp_data_factory_new (gimp, GIMP_TYPE_BRUSH, - (const gchar **) &gimp->config->brush_path, + "brush_path", brush_loader_entries, G_N_ELEMENTS (brush_loader_entries), gimp_brush_new, @@ -589,7 +589,7 @@ gimp_initialize (Gimp *gimp, gimp->pattern_factory = gimp_data_factory_new (gimp, GIMP_TYPE_PATTERN, - (const gchar **) &gimp->config->pattern_path, + "pattern_path", pattern_loader_entries, G_N_ELEMENTS (pattern_loader_entries), gimp_pattern_new, @@ -599,7 +599,7 @@ gimp_initialize (Gimp *gimp, gimp->gradient_factory = gimp_data_factory_new (gimp, GIMP_TYPE_GRADIENT, - (const gchar **) &gimp->config->gradient_path, + "gradient_path", gradient_loader_entries, G_N_ELEMENTS (gradient_loader_entries), gimp_gradient_new, @@ -609,7 +609,7 @@ gimp_initialize (Gimp *gimp, gimp->palette_factory = gimp_data_factory_new (gimp, GIMP_TYPE_PALETTE, - (const gchar **) &gimp->config->palette_path, + "palette_path", palette_loader_entries, G_N_ELEMENTS (palette_loader_entries), gimp_palette_new, diff --git a/app/core/gimpbrush-load.c b/app/core/gimpbrush-load.c index fc687625ce..c0e6582546 100644 --- a/app/core/gimpbrush-load.c +++ b/app/core/gimpbrush-load.c @@ -18,6 +18,7 @@ #include "config.h" +#include #include #include #include @@ -357,19 +358,26 @@ gimp_brush_get_standard (void) } GimpData * -gimp_brush_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_brush_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpBrush *brush; gint fd; g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); fd = open (filename, O_RDONLY | _O_BINARY); if (fd == -1) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); + return NULL; + } - brush = gimp_brush_load_brush (fd, filename); + brush = gimp_brush_load_brush (fd, filename, error); close (fd); @@ -387,6 +395,8 @@ gimp_brush_load (const gchar *filename, temp_buf_swap (brush->pixmap); } + GIMP_DATA (brush)->dirty = FALSE; + return GIMP_DATA (brush); } @@ -483,8 +493,9 @@ gimp_brush_spacing_changed (GimpBrush *brush) } GimpBrush * -gimp_brush_load_brush (gint fd, - const gchar *filename) +gimp_brush_load_brush (gint fd, + const gchar *filename, + GError **error) { GimpBrush *brush; gint bn_size; @@ -494,10 +505,16 @@ gimp_brush_load_brush (gint fd, g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (fd != -1, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); /* Read in the header size */ if (read (fd, &header, sizeof (header)) != sizeof (header)) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Could not read %d bytes from '%s': %s"), + sizeof (header), filename, g_strerror (errno)); + return NULL; + } /* rearrange the bytes in each unsigned int */ header.header_size = g_ntohl (header.header_size); @@ -513,9 +530,10 @@ gimp_brush_load_brush (gint fd, if (header.version != 1 && (header.magic_number != GBRUSH_MAGIC || header.version != 2)) { - g_message (_("Fatal parsing error (unknown version %d):\n" - "Brush file '%s'"), - header.version, filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error (unknown version %d):\n" + "Brush file '%s'"), + header.version, filename); return NULL; } @@ -534,8 +552,10 @@ gimp_brush_load_brush (gint fd, name = g_new (gchar, bn_size); if ((read (fd, name, bn_size)) < bn_size) { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' appears truncated."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' appears truncated."), + filename); g_free (name); return NULL; } @@ -562,8 +582,10 @@ gimp_brush_load_brush (gint fd, temp_buf_data (brush->mask), header.width * header.height) < header.width * header.height) { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' appears truncated."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' appears truncated."), + filename); g_free (name); g_object_unref (G_OBJECT (brush)); return NULL; @@ -572,7 +594,7 @@ gimp_brush_load_brush (gint fd, case 4: brush = GIMP_BRUSH (g_object_new (GIMP_TYPE_BRUSH, NULL)); - brush->mask = temp_buf_new (header.width, header.height, 1, 0, 0, NULL); + brush->mask = temp_buf_new (header.width, header.height, 1, 0, 0, NULL); brush->pixmap = temp_buf_new (header.width, header.height, 3, 0, 0, NULL); for (i = 0; i < header.width * header.height; i++) @@ -581,8 +603,10 @@ gimp_brush_load_brush (gint fd, + i * 3, 3) != 3 || read (fd, temp_buf_data (brush->mask) + i, 1) != 1) { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' appears truncated."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' appears truncated."), + filename); g_free (name); g_object_unref (G_OBJECT (brush)); return NULL; @@ -591,16 +615,16 @@ gimp_brush_load_brush (gint fd, break; default: - g_message ("Unsupported brush depth %d\n" - "in file '%s'.\n" - "GIMP brushes must be GRAY or RGBA.", - header.bytes, filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Unsupported brush depth %d\n" + "in file '%s'.\n" + "GIMP brushes must be GRAY or RGBA."), + header.bytes, filename); g_free (name); return NULL; } gimp_object_set_name (GIMP_OBJECT (brush), name); - g_free (name); brush->spacing = header.spacing; diff --git a/app/core/gimpbrush.c b/app/core/gimpbrush.c index fc687625ce..c0e6582546 100644 --- a/app/core/gimpbrush.c +++ b/app/core/gimpbrush.c @@ -18,6 +18,7 @@ #include "config.h" +#include #include #include #include @@ -357,19 +358,26 @@ gimp_brush_get_standard (void) } GimpData * -gimp_brush_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_brush_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpBrush *brush; gint fd; g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); fd = open (filename, O_RDONLY | _O_BINARY); if (fd == -1) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); + return NULL; + } - brush = gimp_brush_load_brush (fd, filename); + brush = gimp_brush_load_brush (fd, filename, error); close (fd); @@ -387,6 +395,8 @@ gimp_brush_load (const gchar *filename, temp_buf_swap (brush->pixmap); } + GIMP_DATA (brush)->dirty = FALSE; + return GIMP_DATA (brush); } @@ -483,8 +493,9 @@ gimp_brush_spacing_changed (GimpBrush *brush) } GimpBrush * -gimp_brush_load_brush (gint fd, - const gchar *filename) +gimp_brush_load_brush (gint fd, + const gchar *filename, + GError **error) { GimpBrush *brush; gint bn_size; @@ -494,10 +505,16 @@ gimp_brush_load_brush (gint fd, g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (fd != -1, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); /* Read in the header size */ if (read (fd, &header, sizeof (header)) != sizeof (header)) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Could not read %d bytes from '%s': %s"), + sizeof (header), filename, g_strerror (errno)); + return NULL; + } /* rearrange the bytes in each unsigned int */ header.header_size = g_ntohl (header.header_size); @@ -513,9 +530,10 @@ gimp_brush_load_brush (gint fd, if (header.version != 1 && (header.magic_number != GBRUSH_MAGIC || header.version != 2)) { - g_message (_("Fatal parsing error (unknown version %d):\n" - "Brush file '%s'"), - header.version, filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error (unknown version %d):\n" + "Brush file '%s'"), + header.version, filename); return NULL; } @@ -534,8 +552,10 @@ gimp_brush_load_brush (gint fd, name = g_new (gchar, bn_size); if ((read (fd, name, bn_size)) < bn_size) { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' appears truncated."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' appears truncated."), + filename); g_free (name); return NULL; } @@ -562,8 +582,10 @@ gimp_brush_load_brush (gint fd, temp_buf_data (brush->mask), header.width * header.height) < header.width * header.height) { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' appears truncated."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' appears truncated."), + filename); g_free (name); g_object_unref (G_OBJECT (brush)); return NULL; @@ -572,7 +594,7 @@ gimp_brush_load_brush (gint fd, case 4: brush = GIMP_BRUSH (g_object_new (GIMP_TYPE_BRUSH, NULL)); - brush->mask = temp_buf_new (header.width, header.height, 1, 0, 0, NULL); + brush->mask = temp_buf_new (header.width, header.height, 1, 0, 0, NULL); brush->pixmap = temp_buf_new (header.width, header.height, 3, 0, 0, NULL); for (i = 0; i < header.width * header.height; i++) @@ -581,8 +603,10 @@ gimp_brush_load_brush (gint fd, + i * 3, 3) != 3 || read (fd, temp_buf_data (brush->mask) + i, 1) != 1) { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' appears truncated."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' appears truncated."), + filename); g_free (name); g_object_unref (G_OBJECT (brush)); return NULL; @@ -591,16 +615,16 @@ gimp_brush_load_brush (gint fd, break; default: - g_message ("Unsupported brush depth %d\n" - "in file '%s'.\n" - "GIMP brushes must be GRAY or RGBA.", - header.bytes, filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Unsupported brush depth %d\n" + "in file '%s'.\n" + "GIMP brushes must be GRAY or RGBA."), + header.bytes, filename); g_free (name); return NULL; } gimp_object_set_name (GIMP_OBJECT (brush), name); - g_free (name); brush->spacing = header.spacing; diff --git a/app/core/gimpbrush.h b/app/core/gimpbrush.h index d9d8ebf4f2..0e05868f3f 100644 --- a/app/core/gimpbrush.h +++ b/app/core/gimpbrush.h @@ -68,29 +68,31 @@ struct _GimpBrushClass GType gimp_brush_get_type (void) G_GNUC_CONST; -GimpData * gimp_brush_new (const gchar *name, - gboolean stingy_memory_use); +GimpData * gimp_brush_new (const gchar *name, + gboolean stingy_memory_use); GimpData * gimp_brush_get_standard (void); -GimpData * gimp_brush_load (const gchar *filename, - gboolean stingy_memory_use); +GimpData * gimp_brush_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error); -GimpBrush * gimp_brush_load_brush (gint fd, - const gchar *filename); +GimpBrush * gimp_brush_load_brush (gint fd, + const gchar *filename, + GError **error); -GimpBrush * gimp_brush_select_brush (GimpBrush *brush, - GimpCoords *last_coords, - GimpCoords *cur_coords); -gboolean gimp_brush_want_null_motion (GimpBrush *brush, - GimpCoords *last_coords, - GimpCoords *cur_coords); +GimpBrush * gimp_brush_select_brush (GimpBrush *brush, + GimpCoords *last_coords, + GimpCoords *cur_coords); +gboolean gimp_brush_want_null_motion (GimpBrush *brush, + GimpCoords *last_coords, + GimpCoords *cur_coords); -TempBuf * gimp_brush_get_mask (const GimpBrush *brush); -TempBuf * gimp_brush_get_pixmap (const GimpBrush *brush); +TempBuf * gimp_brush_get_mask (const GimpBrush *brush); +TempBuf * gimp_brush_get_pixmap (const GimpBrush *brush); -gint gimp_brush_get_spacing (const GimpBrush *brush); -void gimp_brush_set_spacing (GimpBrush *brush, - gint spacing); -void gimp_brush_spacing_changed (GimpBrush *brush); +gint gimp_brush_get_spacing (const GimpBrush *brush); +void gimp_brush_set_spacing (GimpBrush *brush, + gint spacing); +void gimp_brush_spacing_changed (GimpBrush *brush); #endif /* __GIMP_BRUSH_H__ */ diff --git a/app/core/gimpbrushgenerated-load.c b/app/core/gimpbrushgenerated-load.c index e00a832fe9..b663ae167c 100644 --- a/app/core/gimpbrushgenerated-load.c +++ b/app/core/gimpbrushgenerated-load.c @@ -20,6 +20,7 @@ #include "config.h" +#include #include #include @@ -39,6 +40,8 @@ #include "gimpbrushgenerated.h" +#include "libgimp/gimpintl.h" + #define OVERSAMPLING 5 @@ -47,11 +50,12 @@ static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); static void gimp_brush_generated_init (GimpBrushGenerated *brush); -static gboolean gimp_brush_generated_save (GimpData *data); -static void gimp_brush_generated_dirty (GimpData *data); -static gchar * gimp_brush_generated_get_extension (GimpData *data); -static GimpData * gimp_brush_generated_duplicate (GimpData *data, - gboolean stingy_memory_use); +static gboolean gimp_brush_generated_save (GimpData *data, + GError **error); +static void gimp_brush_generated_dirty (GimpData *data); +static gchar * gimp_brush_generated_get_extension (GimpData *data); +static GimpData * gimp_brush_generated_duplicate (GimpData *data, + gboolean stingy_memory_use); static GimpBrushClass *parent_class = NULL; @@ -111,21 +115,21 @@ gimp_brush_generated_init (GimpBrushGenerated *brush) } static gboolean -gimp_brush_generated_save (GimpData *data) +gimp_brush_generated_save (GimpData *data, + GError **error) { GimpBrushGenerated *brush; FILE *fp; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; - g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (data), FALSE); - brush = GIMP_BRUSH_GENERATED (data); /* we are (finaly) ready to try to save the generated brush file */ if ((fp = fopen (data->filename, "wb")) == NULL) { - g_warning ("Unable to save file %s", data->filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for writing: %s"), + data->filename, g_strerror (errno)); return FALSE; } @@ -369,26 +373,45 @@ gimp_brush_generated_new (gfloat radius, } GimpData * -gimp_brush_generated_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_brush_generated_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpBrushGenerated *brush; FILE *fp; gchar string[256]; + g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + if ((fp = fopen (filename, "rb")) == NULL) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); + return NULL; + } /* make sure the file we are reading is the right type */ fgets (string, 255, fp); - + if (strncmp (string, "GIMP-VBR", 8) != 0) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal Parse Error: '%s' is not a GIMP Brush file"), + filename); + return NULL; + } /* make sure we are reading a compatible version */ fgets (string, 255, fp); if (strncmp (string, "1.0", 3)) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal Parse Error: '%s': unknown GIMP Brush version"), + filename); + return NULL; + } /* create new brush */ brush = GIMP_BRUSH_GENERATED (g_object_new (GIMP_TYPE_BRUSH_GENERATED, NULL)); @@ -427,18 +450,17 @@ gimp_brush_generated_load (const gchar *filename, gimp_brush_generated_thaw (brush); - GIMP_DATA (brush)->dirty = FALSE; - if (stingy_memory_use) temp_buf_swap (GIMP_BRUSH (brush)->mask); + GIMP_DATA (brush)->dirty = FALSE; + return GIMP_DATA (brush); } void gimp_brush_generated_freeze (GimpBrushGenerated *brush) { - g_return_if_fail (brush != NULL); g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush)); brush->freeze++; @@ -447,7 +469,6 @@ gimp_brush_generated_freeze (GimpBrushGenerated *brush) void gimp_brush_generated_thaw (GimpBrushGenerated *brush) { - g_return_if_fail (brush != NULL); g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush)); if (brush->freeze > 0) diff --git a/app/core/gimpbrushgenerated-save.c b/app/core/gimpbrushgenerated-save.c index e00a832fe9..b663ae167c 100644 --- a/app/core/gimpbrushgenerated-save.c +++ b/app/core/gimpbrushgenerated-save.c @@ -20,6 +20,7 @@ #include "config.h" +#include #include #include @@ -39,6 +40,8 @@ #include "gimpbrushgenerated.h" +#include "libgimp/gimpintl.h" + #define OVERSAMPLING 5 @@ -47,11 +50,12 @@ static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); static void gimp_brush_generated_init (GimpBrushGenerated *brush); -static gboolean gimp_brush_generated_save (GimpData *data); -static void gimp_brush_generated_dirty (GimpData *data); -static gchar * gimp_brush_generated_get_extension (GimpData *data); -static GimpData * gimp_brush_generated_duplicate (GimpData *data, - gboolean stingy_memory_use); +static gboolean gimp_brush_generated_save (GimpData *data, + GError **error); +static void gimp_brush_generated_dirty (GimpData *data); +static gchar * gimp_brush_generated_get_extension (GimpData *data); +static GimpData * gimp_brush_generated_duplicate (GimpData *data, + gboolean stingy_memory_use); static GimpBrushClass *parent_class = NULL; @@ -111,21 +115,21 @@ gimp_brush_generated_init (GimpBrushGenerated *brush) } static gboolean -gimp_brush_generated_save (GimpData *data) +gimp_brush_generated_save (GimpData *data, + GError **error) { GimpBrushGenerated *brush; FILE *fp; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; - g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (data), FALSE); - brush = GIMP_BRUSH_GENERATED (data); /* we are (finaly) ready to try to save the generated brush file */ if ((fp = fopen (data->filename, "wb")) == NULL) { - g_warning ("Unable to save file %s", data->filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for writing: %s"), + data->filename, g_strerror (errno)); return FALSE; } @@ -369,26 +373,45 @@ gimp_brush_generated_new (gfloat radius, } GimpData * -gimp_brush_generated_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_brush_generated_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpBrushGenerated *brush; FILE *fp; gchar string[256]; + g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + if ((fp = fopen (filename, "rb")) == NULL) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); + return NULL; + } /* make sure the file we are reading is the right type */ fgets (string, 255, fp); - + if (strncmp (string, "GIMP-VBR", 8) != 0) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal Parse Error: '%s' is not a GIMP Brush file"), + filename); + return NULL; + } /* make sure we are reading a compatible version */ fgets (string, 255, fp); if (strncmp (string, "1.0", 3)) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal Parse Error: '%s': unknown GIMP Brush version"), + filename); + return NULL; + } /* create new brush */ brush = GIMP_BRUSH_GENERATED (g_object_new (GIMP_TYPE_BRUSH_GENERATED, NULL)); @@ -427,18 +450,17 @@ gimp_brush_generated_load (const gchar *filename, gimp_brush_generated_thaw (brush); - GIMP_DATA (brush)->dirty = FALSE; - if (stingy_memory_use) temp_buf_swap (GIMP_BRUSH (brush)->mask); + GIMP_DATA (brush)->dirty = FALSE; + return GIMP_DATA (brush); } void gimp_brush_generated_freeze (GimpBrushGenerated *brush) { - g_return_if_fail (brush != NULL); g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush)); brush->freeze++; @@ -447,7 +469,6 @@ gimp_brush_generated_freeze (GimpBrushGenerated *brush) void gimp_brush_generated_thaw (GimpBrushGenerated *brush) { - g_return_if_fail (brush != NULL); g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush)); if (brush->freeze > 0) diff --git a/app/core/gimpbrushgenerated.c b/app/core/gimpbrushgenerated.c index e00a832fe9..b663ae167c 100644 --- a/app/core/gimpbrushgenerated.c +++ b/app/core/gimpbrushgenerated.c @@ -20,6 +20,7 @@ #include "config.h" +#include #include #include @@ -39,6 +40,8 @@ #include "gimpbrushgenerated.h" +#include "libgimp/gimpintl.h" + #define OVERSAMPLING 5 @@ -47,11 +50,12 @@ static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); static void gimp_brush_generated_init (GimpBrushGenerated *brush); -static gboolean gimp_brush_generated_save (GimpData *data); -static void gimp_brush_generated_dirty (GimpData *data); -static gchar * gimp_brush_generated_get_extension (GimpData *data); -static GimpData * gimp_brush_generated_duplicate (GimpData *data, - gboolean stingy_memory_use); +static gboolean gimp_brush_generated_save (GimpData *data, + GError **error); +static void gimp_brush_generated_dirty (GimpData *data); +static gchar * gimp_brush_generated_get_extension (GimpData *data); +static GimpData * gimp_brush_generated_duplicate (GimpData *data, + gboolean stingy_memory_use); static GimpBrushClass *parent_class = NULL; @@ -111,21 +115,21 @@ gimp_brush_generated_init (GimpBrushGenerated *brush) } static gboolean -gimp_brush_generated_save (GimpData *data) +gimp_brush_generated_save (GimpData *data, + GError **error) { GimpBrushGenerated *brush; FILE *fp; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; - g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (data), FALSE); - brush = GIMP_BRUSH_GENERATED (data); /* we are (finaly) ready to try to save the generated brush file */ if ((fp = fopen (data->filename, "wb")) == NULL) { - g_warning ("Unable to save file %s", data->filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for writing: %s"), + data->filename, g_strerror (errno)); return FALSE; } @@ -369,26 +373,45 @@ gimp_brush_generated_new (gfloat radius, } GimpData * -gimp_brush_generated_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_brush_generated_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpBrushGenerated *brush; FILE *fp; gchar string[256]; + g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + if ((fp = fopen (filename, "rb")) == NULL) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); + return NULL; + } /* make sure the file we are reading is the right type */ fgets (string, 255, fp); - + if (strncmp (string, "GIMP-VBR", 8) != 0) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal Parse Error: '%s' is not a GIMP Brush file"), + filename); + return NULL; + } /* make sure we are reading a compatible version */ fgets (string, 255, fp); if (strncmp (string, "1.0", 3)) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal Parse Error: '%s': unknown GIMP Brush version"), + filename); + return NULL; + } /* create new brush */ brush = GIMP_BRUSH_GENERATED (g_object_new (GIMP_TYPE_BRUSH_GENERATED, NULL)); @@ -427,18 +450,17 @@ gimp_brush_generated_load (const gchar *filename, gimp_brush_generated_thaw (brush); - GIMP_DATA (brush)->dirty = FALSE; - if (stingy_memory_use) temp_buf_swap (GIMP_BRUSH (brush)->mask); + GIMP_DATA (brush)->dirty = FALSE; + return GIMP_DATA (brush); } void gimp_brush_generated_freeze (GimpBrushGenerated *brush) { - g_return_if_fail (brush != NULL); g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush)); brush->freeze++; @@ -447,7 +469,6 @@ gimp_brush_generated_freeze (GimpBrushGenerated *brush) void gimp_brush_generated_thaw (GimpBrushGenerated *brush) { - g_return_if_fail (brush != NULL); g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush)); if (brush->freeze > 0) diff --git a/app/core/gimpbrushgenerated.h b/app/core/gimpbrushgenerated.h index 7bc99de45d..381514fd1e 100644 --- a/app/core/gimpbrushgenerated.h +++ b/app/core/gimpbrushgenerated.h @@ -65,7 +65,8 @@ GimpData * gimp_brush_generated_new (gfloat radius, gfloat aspect_ratio, gboolean stingy_memory_use); GimpData * gimp_brush_generated_load (const gchar *file_name, - gboolean stingy_memory_use); + gboolean stingy_memory_use, + GError **error); void gimp_brush_generated_freeze (GimpBrushGenerated *brush); void gimp_brush_generated_thaw (GimpBrushGenerated *brush); diff --git a/app/core/gimpbrushpipe-load.c b/app/core/gimpbrushpipe-load.c index ea3b9d1323..8a65d47834 100644 --- a/app/core/gimpbrushpipe-load.c +++ b/app/core/gimpbrushpipe-load.c @@ -294,8 +294,9 @@ gimp_brush_pipe_want_null_motion (GimpBrush *brush, } GimpData * -gimp_brush_pipe_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_brush_pipe_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpBrushPipe *pipe = NULL; GimpPixPipeParams params; @@ -308,12 +309,14 @@ gimp_brush_pipe_load (const gchar *filename, gint fd; g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); fd = open (filename, O_RDONLY | _O_BINARY); if (fd == -1) { - g_message (_("Failed to open file: '%s': %s"), - filename, g_strerror (errno)); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Failed to open '%s' for reading: %s"), + filename, g_strerror (errno)); return NULL; } @@ -343,8 +346,10 @@ gimp_brush_pipe_load (const gchar *filename, if (!pipe) { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' is corrupt."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' is corrupt."), + filename); close (fd); return NULL; } @@ -361,8 +366,10 @@ gimp_brush_pipe_load (const gchar *filename, if (num_of_brushes < 1) { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' is corrupt."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' is corrupt."), + filename); close (fd); g_object_unref (G_OBJECT (pipe)); g_string_free (buffer, TRUE); @@ -440,7 +447,7 @@ gimp_brush_pipe_load (const gchar *filename, while (pipe->nbrushes < num_of_brushes) { - pipe->brushes[pipe->nbrushes] = gimp_brush_load_brush (fd, filename); + pipe->brushes[pipe->nbrushes] = gimp_brush_load_brush (fd, filename, NULL); if (pipe->brushes[pipe->nbrushes]) { @@ -449,8 +456,10 @@ gimp_brush_pipe_load (const gchar *filename, } else { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' is corrupt."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' is corrupt."), + filename); close (fd); g_object_unref (G_OBJECT (pipe)); return NULL; @@ -473,5 +482,7 @@ gimp_brush_pipe_load (const gchar *filename, close (fd); + GIMP_DATA (pipe)->dirty = FALSE; + return GIMP_DATA (pipe); } diff --git a/app/core/gimpbrushpipe.c b/app/core/gimpbrushpipe.c index ea3b9d1323..8a65d47834 100644 --- a/app/core/gimpbrushpipe.c +++ b/app/core/gimpbrushpipe.c @@ -294,8 +294,9 @@ gimp_brush_pipe_want_null_motion (GimpBrush *brush, } GimpData * -gimp_brush_pipe_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_brush_pipe_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpBrushPipe *pipe = NULL; GimpPixPipeParams params; @@ -308,12 +309,14 @@ gimp_brush_pipe_load (const gchar *filename, gint fd; g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); fd = open (filename, O_RDONLY | _O_BINARY); if (fd == -1) { - g_message (_("Failed to open file: '%s': %s"), - filename, g_strerror (errno)); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Failed to open '%s' for reading: %s"), + filename, g_strerror (errno)); return NULL; } @@ -343,8 +346,10 @@ gimp_brush_pipe_load (const gchar *filename, if (!pipe) { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' is corrupt."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' is corrupt."), + filename); close (fd); return NULL; } @@ -361,8 +366,10 @@ gimp_brush_pipe_load (const gchar *filename, if (num_of_brushes < 1) { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' is corrupt."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' is corrupt."), + filename); close (fd); g_object_unref (G_OBJECT (pipe)); g_string_free (buffer, TRUE); @@ -440,7 +447,7 @@ gimp_brush_pipe_load (const gchar *filename, while (pipe->nbrushes < num_of_brushes) { - pipe->brushes[pipe->nbrushes] = gimp_brush_load_brush (fd, filename); + pipe->brushes[pipe->nbrushes] = gimp_brush_load_brush (fd, filename, NULL); if (pipe->brushes[pipe->nbrushes]) { @@ -449,8 +456,10 @@ gimp_brush_pipe_load (const gchar *filename, } else { - g_message (_("Fatal parsing error:\n" - "Brush file '%s' is corrupt."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\n" + "Brush file '%s' is corrupt."), + filename); close (fd); g_object_unref (G_OBJECT (pipe)); return NULL; @@ -473,5 +482,7 @@ gimp_brush_pipe_load (const gchar *filename, close (fd); + GIMP_DATA (pipe)->dirty = FALSE; + return GIMP_DATA (pipe); } diff --git a/app/core/gimpbrushpipe.h b/app/core/gimpbrushpipe.h index 35074e591d..7d4d005acd 100644 --- a/app/core/gimpbrushpipe.h +++ b/app/core/gimpbrushpipe.h @@ -75,8 +75,9 @@ struct _GimpBrushPipeClass GType gimp_brush_pipe_get_type (void) G_GNUC_CONST; -GimpData * gimp_brush_pipe_load (const gchar *filename, - gboolean stingy_memory_use); +GimpData * gimp_brush_pipe_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error); #endif /* __GIMP_BRUSH_PIPE_H__ */ diff --git a/app/core/gimpdata.c b/app/core/gimpdata.c index 9a964c2c59..7c98c43fd5 100644 --- a/app/core/gimpdata.c +++ b/app/core/gimpdata.c @@ -43,9 +43,6 @@ enum { DIRTY, - SAVE, - GET_EXTENSION, - DUPLICATE, LAST_SIGNAL }; @@ -114,34 +111,6 @@ gimp_data_class_init (GimpDataClass *klass) gimp_marshal_VOID__VOID, G_TYPE_NONE, 0); - data_signals[SAVE] = - g_signal_new ("save", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GimpDataClass, save), - NULL, NULL, - gimp_marshal_BOOLEAN__VOID, - G_TYPE_BOOLEAN, 0); - - data_signals[GET_EXTENSION] = - g_signal_new ("get_extension", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GimpDataClass, get_extension), - NULL, NULL, - gimp_marshal_POINTER__VOID, - G_TYPE_POINTER, 0); - - data_signals[DUPLICATE] = - g_signal_new ("duplicate", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GimpDataClass, duplicate), - NULL, NULL, - gimp_marshal_OBJECT__BOOLEAN, - GIMP_TYPE_DATA, 1, - G_TYPE_BOOLEAN); - object_class->finalize = gimp_data_finalize; gimp_object_class->name_changed = gimp_data_name_changed; @@ -201,11 +170,14 @@ gimp_data_get_memsize (GimpObject *object) } gboolean -gimp_data_save (GimpData *data) +gimp_data_save (GimpData *data, + GError **error) { gboolean success = FALSE; g_return_val_if_fail (GIMP_IS_DATA (data), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + g_return_val_if_fail (data->filename != NULL, FALSE); if (data->internal) { @@ -213,15 +185,8 @@ gimp_data_save (GimpData *data) return TRUE; } - if (! data->filename) - { - g_warning ("%s(): can't save data with NULL filename", - G_GNUC_FUNCTION); - return FALSE; - } - - g_signal_emit (G_OBJECT (data), data_signals[SAVE], 0, - &success); + if (GIMP_DATA_GET_CLASS (data)->save) + success = GIMP_DATA_GET_CLASS (data)->save (data, error); if (success) data->dirty = FALSE; @@ -258,7 +223,7 @@ gimp_data_delete_from_disk (GimpData *data, if (unlink (data->filename) == -1) { - g_set_error (error, 0, 0, + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_DELETE, _("Could not delete '%s': %s"), data->filename, g_strerror (errno)); return FALSE; @@ -270,14 +235,12 @@ gimp_data_delete_from_disk (GimpData *data, const gchar * gimp_data_get_extension (GimpData *data) { - const gchar *extension = NULL; - g_return_val_if_fail (GIMP_IS_DATA (data), NULL); - g_signal_emit (G_OBJECT (data), data_signals[GET_EXTENSION], 0, - &extension); + if (GIMP_DATA_GET_CLASS (data)->get_extension) + return GIMP_DATA_GET_CLASS (data)->get_extension (data); - return extension; + return NULL; } void @@ -306,7 +269,6 @@ gimp_data_create_filename (GimpData *data, gchar *safe_name; gint i; gint unum = 1; - FILE *file; g_return_if_fail (GIMP_IS_DATA (data)); g_return_if_fail (basename != NULL); @@ -334,22 +296,18 @@ gimp_data_create_filename (GimpData *data, g_free (filename); - while ((file = fopen (fullpath, "r"))) + while (g_file_test (fullpath, G_FILE_TEST_EXISTS)) { - fclose (file); - g_free (fullpath); - filename = g_strdup_printf ("%s_%d%s", + filename = g_strdup_printf ("%s-%d%s", safe_name, - unum, + unum++, gimp_data_get_extension (data)); fullpath = g_build_filename (dir, filename, NULL); g_free (filename); - - unum++; } g_free (dir); @@ -364,10 +322,20 @@ GimpData * gimp_data_duplicate (GimpData *data, gboolean stingy_memory_use) { - GimpData *new_data = NULL; + g_return_val_if_fail (GIMP_IS_DATA (data), NULL); - g_signal_emit (G_OBJECT (data), data_signals[DUPLICATE], 0, - stingy_memory_use, &new_data); + if (GIMP_DATA_GET_CLASS (data)->duplicate) + return GIMP_DATA_GET_CLASS (data)->duplicate (data, stingy_memory_use); - return new_data; + return NULL; +} + +GQuark +gimp_data_error_quark (void) +{ + static GQuark q = 0; + if (q == 0) + q = g_quark_from_static_string ("gimp-data-error-quark"); + + return q; } diff --git a/app/core/gimpdata.h b/app/core/gimpdata.h index f630b7b490..e0c5936477 100644 --- a/app/core/gimpdata.h +++ b/app/core/gimpdata.h @@ -26,6 +26,15 @@ #include "gimpviewable.h" +typedef enum +{ + GIMP_DATA_ERROR_OPEN, /* opening data file failed */ + GIMP_DATA_ERROR_READ, /* reading data file failed */ + GIMP_DATA_ERROR_WRITE, /* writing data file failed */ + GIMP_DATA_ERROR_DELETE /* deleting data file failed */ +} GimpDataError; + + #define GIMP_TYPE_DATA (gimp_data_get_type ()) #define GIMP_DATA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_DATA, GimpData)) #define GIMP_DATA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_DATA, GimpDataClass)) @@ -49,17 +58,22 @@ struct _GimpDataClass { GimpViewableClass parent_class; - void (* dirty) (GimpData *data); - gboolean (* save) (GimpData *data); - gchar * (* get_extension) (GimpData *data); - GimpData * (* duplicate) (GimpData *data, + /* signals */ + void (* dirty) (GimpData *data); + + /* virtual functions */ + gboolean (* save) (GimpData *data, + GError **error); + gchar * (* get_extension) (GimpData *data); + GimpData * (* duplicate) (GimpData *data, gboolean stingy_memory_use); }; GType gimp_data_get_type (void) G_GNUC_CONST; -gboolean gimp_data_save (GimpData *data); +gboolean gimp_data_save (GimpData *data, + GError **error); void gimp_data_dirty (GimpData *data); gboolean gimp_data_delete_from_disk (GimpData *data, @@ -70,11 +84,16 @@ const gchar * gimp_data_get_extension (GimpData *data); void gimp_data_set_filename (GimpData *data, const gchar *filename); void gimp_data_create_filename (GimpData *data, - const gchar *filename, + const gchar *basename, const gchar *data_path); GimpData * gimp_data_duplicate (GimpData *data, gboolean stingy_memory_use); +#define GIMP_DATA_ERROR (gimp_data_error_quark ()) + +GQuark gimp_data_error_quark (void) G_GNUC_CONST; + + #endif /* __GIMP_DATA_H__ */ diff --git a/app/core/gimpdatafactory.c b/app/core/gimpdatafactory.c index f95c1bb0c2..ed8fc5e95b 100644 --- a/app/core/gimpdatafactory.c +++ b/app/core/gimpdatafactory.c @@ -21,6 +21,9 @@ #include "config.h" +#include +#include + #include #include "libgimpbase/gimpbase.h" @@ -38,14 +41,14 @@ #include "libgimp/gimpintl.h" -static void gimp_data_factory_class_init (GimpDataFactoryClass *klass); -static void gimp_data_factory_init (GimpDataFactory *factory); +static void gimp_data_factory_class_init (GimpDataFactoryClass *klass); +static void gimp_data_factory_init (GimpDataFactory *factory); -static void gimp_data_factory_finalize (GObject *object); +static void gimp_data_factory_finalize (GObject *object); -static gsize gimp_data_factory_get_memsize (GimpObject *object); +static gsize gimp_data_factory_get_memsize (GimpObject *object); -static void gimp_data_factory_data_load_callback (GimpDatafileData *file_data); +static void gimp_data_factory_load_callback (GimpDatafileData *file_data); static GimpObjectClass *parent_class = NULL; @@ -100,7 +103,7 @@ gimp_data_factory_init (GimpDataFactory *factory) { factory->gimp = NULL; factory->container = NULL; - factory->data_path = NULL; + factory->path_property_name = NULL; factory->loader_entries = NULL; factory->n_loader_entries = 0; factory->data_new_func = NULL; @@ -116,10 +119,16 @@ gimp_data_factory_finalize (GObject *object) if (factory->container) { - g_object_unref (G_OBJECT (factory->container)); + g_object_unref (factory->container); factory->container = NULL; } + if (factory->path_property_name) + { + g_free (factory->path_property_name); + factory->path_property_name = NULL; + } + G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -137,19 +146,19 @@ gimp_data_factory_get_memsize (GimpObject *object) } GimpDataFactory * -gimp_data_factory_new (Gimp *gimp, - GType data_type, - const gchar **data_path, - const GimpDataFactoryLoaderEntry *loader_entries, - gint n_loader_entries, - GimpDataNewFunc new_func, - GimpDataGetStandardFunc standard_func) +gimp_data_factory_new (Gimp *gimp, + GType data_type, + const gchar *path_property_name, + const GimpDataFactoryLoaderEntry *loader_entries, + gint n_loader_entries, + GimpDataNewFunc new_func, + GimpDataGetStandardFunc standard_func) { GimpDataFactory *factory; g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); g_return_val_if_fail (g_type_is_a (data_type, GIMP_TYPE_DATA), NULL); - g_return_val_if_fail (data_path != NULL, NULL); + g_return_val_if_fail (path_property_name != NULL, NULL); g_return_val_if_fail (loader_entries != NULL, NULL); g_return_val_if_fail (n_loader_entries > 0, NULL); @@ -158,7 +167,7 @@ gimp_data_factory_new (Gimp *gimp, factory->gimp = gimp; factory->container = gimp_data_list_new (data_type); - factory->data_path = data_path; + factory->path_property_name = g_strdup (path_property_name); factory->loader_entries = loader_entries; factory->n_loader_entries = n_loader_entries; @@ -173,57 +182,86 @@ void gimp_data_factory_data_init (GimpDataFactory *factory, gboolean no_data /* FIXME */) { + gchar *path = NULL; + g_return_if_fail (GIMP_IS_DATA_FACTORY (factory)); gimp_container_freeze (factory->container); gimp_data_factory_data_free (factory); - if (factory->data_path && *factory->data_path) + g_object_get (G_OBJECT (factory->gimp->config), + factory->path_property_name, &path, + NULL); + + if (path && strlen (path)) { - gimp_datafiles_read_directories (*factory->data_path, + gimp_datafiles_read_directories (path, G_FILE_TEST_EXISTS, - gimp_data_factory_data_load_callback, + gimp_data_factory_load_callback, factory); } + g_free (path); + gimp_container_thaw (factory->container); } void gimp_data_factory_data_save (GimpDataFactory *factory) { - GimpList *gimp_list; - GList *list; + gchar *path = NULL; g_return_if_fail (GIMP_IS_DATA_FACTORY (factory)); if (gimp_container_num_children (factory->container) == 0) return; - if (! (factory->data_path && *factory->data_path)) - return; + g_object_get (G_OBJECT (factory->gimp->config), + factory->path_property_name, &path, + NULL); - gimp_list = GIMP_LIST (factory->container); - - gimp_container_freeze (factory->container); - - for (list = gimp_list->list; list; list = g_list_next (list)) + if (path && strlen (path)) { - GimpData *data; + GimpList *gimp_list; + GList *list; - data = GIMP_DATA (list->data); + gimp_list = GIMP_LIST (factory->container); - if (! data->filename) - gimp_data_create_filename (data, - GIMP_OBJECT (data)->name, - *factory->data_path); + gimp_container_freeze (factory->container); - if (data->dirty) - gimp_data_save (data); + for (list = gimp_list->list; list; list = g_list_next (list)) + { + GimpData *data; + + data = GIMP_DATA (list->data); + + if (! data->filename) + gimp_data_create_filename (data, GIMP_OBJECT (data)->name, path); + + if (data->dirty) + { + GError *error = NULL; + + if (! gimp_data_save (data, &error)) + { + /* check if there actually was an error (no error + * means the data class does not implement save) + */ + if (error) + { + g_message (_("Warning: Failed to save data:\n%s"), + error->message); + g_clear_error (&error); + } + } + } + } + + gimp_container_thaw (factory->container); } - gimp_container_thaw (factory->container); + g_free (path); } void @@ -302,6 +340,57 @@ gimp_data_factory_data_new (GimpDataFactory *factory, return NULL; } +GimpData * +gimp_data_factory_data_duplicate (GimpDataFactory *factory, + GimpData *data) +{ + GimpBaseConfig *base_config; + GimpData *new_data; + + g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL); + g_return_val_if_fail (GIMP_IS_DATA (data), NULL); + + base_config = GIMP_BASE_CONFIG (factory->gimp->config); + + new_data = gimp_data_duplicate (data, base_config->stingy_memory_use); + + if (new_data) + { + const gchar *name; + gchar *ext; + gint copy_len; + gint number; + gchar *new_name; + + name = gimp_object_get_name (GIMP_OBJECT (data)); + + ext = strrchr (name, '#'); + copy_len = strlen (_("copy")); + + if ((strlen (name) >= copy_len && + strcmp (&name[strlen (name) - copy_len], _("copy")) == 0) || + (ext && (number = atoi (ext + 1)) > 0 && + ((gint) (log10 (number) + 1)) == strlen (ext + 1))) + { + /* don't have redundant "copy"s */ + new_name = g_strdup (name); + } + else + { + new_name = g_strdup_printf (_("%s copy"), name); + } + + gimp_object_set_name (GIMP_OBJECT (new_data), new_name); + + g_free (new_name); + + gimp_container_add (factory->container, GIMP_OBJECT (new_data)); + g_object_unref (new_data); + } + + return new_data; +} + GimpData * gimp_data_factory_data_get_standard (GimpDataFactory *factory) { @@ -314,7 +403,7 @@ gimp_data_factory_data_get_standard (GimpDataFactory *factory) } static void -gimp_data_factory_data_load_callback (GimpDatafileData *file_data) +gimp_data_factory_load_callback (GimpDatafileData *file_data) { GimpDataFactory *factory; gint i; @@ -347,16 +436,20 @@ gimp_data_factory_data_load_callback (GimpDatafileData *file_data) { GimpBaseConfig *base_config; GimpData *data; + GError *error = NULL; base_config = GIMP_BASE_CONFIG (factory->gimp->config); data = (GimpData *) (* factory->loader_entries[i].load_func) (file_data->filename, - base_config->stingy_memory_use); + base_config->stingy_memory_use, + &error); if (! data) { - g_message (_("Warning: Failed to load data from\n'%s'"), file_data->filename); + g_message (_("Warning: Failed to load data:\n%s"), + error->message); + g_clear_error (&error); } else { diff --git a/app/core/gimpdatafactory.h b/app/core/gimpdatafactory.h index 90c21ba129..9f27e67f82 100644 --- a/app/core/gimpdatafactory.h +++ b/app/core/gimpdatafactory.h @@ -26,10 +26,11 @@ #include "gimpobject.h" -typedef GimpData * (* GimpDataNewFunc) (const gchar *name, - gboolean stingy_memory_use); -typedef GimpData * (* GimpDataLoadFunc) (const gchar *filename, - gboolean stingy_memory_use); +typedef GimpData * (* GimpDataNewFunc) (const gchar *name, + gboolean stingy_memory_use); +typedef GimpData * (* GimpDataLoadFunc) (const gchar *filename, + gboolean stingy_memory_use, + GError **error); typedef GimpData * (* GimpDataGetStandardFunc) (void); @@ -54,18 +55,18 @@ typedef struct _GimpDataFactoryClass GimpDataFactoryClass; struct _GimpDataFactory { - GimpObject parent_instance; + GimpObject parent_instance; - Gimp *gimp; - GimpContainer *container; + Gimp *gimp; + GimpContainer *container; - const gchar **data_path; + gchar *path_property_name; - const GimpDataFactoryLoaderEntry *loader_entries; - gint n_loader_entries; + const GimpDataFactoryLoaderEntry *loader_entries; + gint n_loader_entries; - GimpDataNewFunc data_new_func; - GimpDataGetStandardFunc data_get_standard_func; + GimpDataNewFunc data_new_func; + GimpDataGetStandardFunc data_get_standard_func; }; struct _GimpDataFactoryClass @@ -76,13 +77,13 @@ struct _GimpDataFactoryClass GType gimp_data_factory_get_type (void) G_GNUC_CONST; -GimpDataFactory * gimp_data_factory_new (Gimp *gimp, - GType data_type, - const gchar **data_path, - const GimpDataFactoryLoaderEntry *loader_entries, - gint n_loader_entries, - GimpDataNewFunc new_func, - GimpDataGetStandardFunc standard_func); +GimpDataFactory * gimp_data_factory_new (Gimp *gimp, + GType data_type, + const gchar *path_property_name, + const GimpDataFactoryLoaderEntry *loader_entries, + gint n_loader_entries, + GimpDataNewFunc new_func, + GimpDataGetStandardFunc standard_func); void gimp_data_factory_data_init (GimpDataFactory *factory, gboolean no_data); @@ -92,8 +93,7 @@ void gimp_data_factory_data_free (GimpDataFactory *factory); GimpData * gimp_data_factory_data_new (GimpDataFactory *factory, const gchar *name); GimpData * gimp_data_factory_data_duplicate (GimpDataFactory *factory, - GimpData *data, - const gchar *name); + GimpData *data); GimpData * gimp_data_factory_data_get_standard (GimpDataFactory *factory); diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c index 0122451a1b..83b726d1cc 100644 --- a/app/core/gimpgradient.c +++ b/app/core/gimpgradient.c @@ -53,7 +53,8 @@ static TempBuf * gimp_gradient_get_new_preview (GimpViewable *viewable, gint width, gint height); static void gimp_gradient_dirty (GimpData *data); -static gboolean gimp_gradient_save (GimpData *data); +static gboolean gimp_gradient_save (GimpData *data, + GError **error); static gchar * gimp_gradient_get_extension (GimpData *data); static GimpData * gimp_gradient_duplicate (GimpData *data, gboolean stingy_memory_use); @@ -314,8 +315,9 @@ gimp_gradient_get_standard (void) } GimpData * -gimp_gradient_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_gradient_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpGradient *gradient; GimpGradientSegment *seg; @@ -327,14 +329,23 @@ gimp_gradient_load (const gchar *filename, gchar line[1024]; g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); file = fopen (filename, "rb"); if (!file) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); + return NULL; + } fgets (line, 1024, file); if (strcmp (line, "GIMP Gradient\n") != 0) { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal Parse Error: '%s' is not a GIMP Gradient file"), + filename); fclose (file); return NULL; } @@ -367,7 +378,6 @@ gimp_gradient_load (const gchar *filename, basename = g_path_get_basename (filename); gimp_object_set_name (GIMP_OBJECT (gradient), basename); - g_free (basename); } @@ -375,8 +385,9 @@ gimp_gradient_load (const gchar *filename, if (num_segments < 1) { - g_message ("Fatal parsing error:\nGradient file '%s' is corrupt.", - filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error:\nGradient file '%s' is corrupt."), + filename); g_object_unref (G_OBJECT (gradient)); fclose (file); return NULL; @@ -459,7 +470,8 @@ gimp_gradient_dirty (GimpData *data) } static gboolean -gimp_gradient_save (GimpData *data) +gimp_gradient_save (GimpData *data, + GError **error) { GimpGradient *gradient; GimpGradientSegment *seg; @@ -471,7 +483,9 @@ gimp_gradient_save (GimpData *data) file = fopen (data->filename, "wb"); if (! file) { - g_message (_("Unable to save '%s':\n%s"), data->filename, g_strerror (errno)); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for writing: %s"), + data->filename, g_strerror (errno)); return FALSE; } @@ -536,10 +550,98 @@ gimp_gradient_get_extension (GimpData *data) return GIMP_GRADIENT_FILE_EXTENSION; } +gboolean +gimp_gradient_save_as_pov (GimpGradient *gradient, + const gchar *filename, + GError **error) +{ + FILE *file; + GimpGradientSegment *seg; + gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; + gchar color_buf[4][G_ASCII_DTOSTR_BUF_SIZE]; + + g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + file = fopen (filename, "wb"); + + if (! file) + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for writing: %s"), + filename, g_strerror (errno)); + return FALSE; + } + else + { + fprintf (file, "/* color_map file created by the GIMP */\n"); + fprintf (file, "/* http://www.gimp.org/ */\n"); + + fprintf (file, "color_map {\n"); + + for (seg = gradient->segments; seg; seg = seg->next) + { + /* Left */ + g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", + seg->left); + g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", + seg->left_color.r); + g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", + seg->left_color.g); + g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", + seg->left_color.b); + g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", + 1.0 - seg->left_color.a); + + fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n", + buf, + color_buf[0], color_buf[1], color_buf[2], color_buf[3]); + + /* Middle */ + g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", + seg->middle); + g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", + (seg->left_color.r + seg->right_color.r) / 2.0); + g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", + (seg->left_color.g + seg->right_color.g) / 2.0); + g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", + (seg->left_color.b + seg->right_color.b) / 2.0); + g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", + 1.0 - (seg->left_color.a + seg->right_color.a) / 2.0); + + fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n", + buf, + color_buf[0], color_buf[1], color_buf[2], color_buf[3]); + + /* Right */ + g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", + seg->right); + g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", + seg->right_color.r); + g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", + seg->right_color.g); + g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", + seg->right_color.b); + g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", + 1.0 - seg->right_color.a); + + fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n", + buf, + color_buf[0], color_buf[1], color_buf[2], color_buf[3]); + } + + fprintf (file, "} /* color_map */\n"); + fclose (file); + } + + return TRUE; +} + void gimp_gradient_get_color_at (GimpGradient *gradient, - gdouble pos, - GimpRGB *color) + gdouble pos, + GimpRGB *color) { gdouble factor = 0.0; GimpGradientSegment *seg; diff --git a/app/core/gimpgradient.h b/app/core/gimpgradient.h index c130c889c7..62179c706c 100644 --- a/app/core/gimpgradient.h +++ b/app/core/gimpgradient.h @@ -75,7 +75,12 @@ GimpData * gimp_gradient_new (const gchar *name, gboolean stingy_memory_use); GimpData * gimp_gradient_get_standard (void); GimpData * gimp_gradient_load (const gchar *filename, - gboolean stingy_memory_use); + gboolean stingy_memory_use, + GError **error); + +gboolean gimp_gradient_save_as_pov (GimpGradient *gradient, + const gchar *filename, + GError **error); void gimp_gradient_get_color_at (GimpGradient *gradient, gdouble pos, diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c index acb2d270a6..c86fb2698c 100644 --- a/app/core/gimppalette-load.c +++ b/app/core/gimppalette-load.c @@ -52,7 +52,8 @@ static TempBuf * gimp_palette_get_new_preview (GimpViewable *viewable, gint width, gint height); static void gimp_palette_dirty (GimpData *data); -static gboolean gimp_palette_save (GimpData *data); +static gboolean gimp_palette_save (GimpData *data, + GError **error); static gchar * gimp_palette_get_extension (GimpData *data); static void gimp_palette_entry_free (GimpPaletteEntry *entry); @@ -273,8 +274,9 @@ gimp_palette_get_standard (void) } GimpData * -gimp_palette_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_palette_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpPalette *palette; gchar str[1024]; @@ -286,14 +288,16 @@ gimp_palette_load (const gchar *filename, g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (*filename != '\0', NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); r = g = b = 0; /* Open the requested file */ if (! (fp = fopen (filename, "r"))) { - g_message (_("Failed to open palette file '%s': %s"), - filename, g_strerror (errno)); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); return NULL; } @@ -306,12 +310,16 @@ gimp_palette_load (const gchar *filename, { /* bad magic, but maybe it has \r\n at the end of lines? */ if (!strcmp (str, "GIMP Palette\r")) - g_message (_("Loading palette '%s':\n" - "Corrupt palette: missing magic header\n" - "Does this file need converting from DOS?"), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\n" + "Corrupt palette: missing magic header\n" + "Does this file need converting from DOS?"), + filename); else - g_message (_("Loading palette '%s':\n" - "Corrupt palette: missing magic header"), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\n" + "Corrupt palette: missing magic header"), + filename); fclose (fp); @@ -324,9 +332,9 @@ gimp_palette_load (const gchar *filename, if (! fgets (str, 1024, fp)) { - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -349,9 +357,9 @@ gimp_palette_load (const gchar *filename, if (! fgets (str, 1024, fp)) { - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -370,7 +378,6 @@ gimp_palette_load (const gchar *filename, g_message (_("Loading palette '%s':\n" "Invalid number of columns in line %d."), filename, linenum); - columns = 0; } @@ -378,9 +385,9 @@ gimp_palette_load (const gchar *filename, if (! fgets (str, 1024, fp)) { - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -396,7 +403,6 @@ gimp_palette_load (const gchar *filename, basename = g_path_get_basename (filename); gimp_object_set_name (GIMP_OBJECT (palette), basename); - g_free (basename); } @@ -449,9 +455,9 @@ gimp_palette_load (const gchar *filename, if (feof (fp)) break; - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -475,7 +481,8 @@ gimp_palette_dirty (GimpData *data) } static gboolean -gimp_palette_save (GimpData *data) +gimp_palette_save (GimpData *data, + GError **error) { GimpPalette *palette; GimpPaletteEntry *entry; @@ -485,10 +492,11 @@ gimp_palette_save (GimpData *data) palette = GIMP_PALETTE (data); - if (! (fp = fopen (GIMP_DATA (palette)->filename, "w"))) + if (! (fp = fopen (data->filename, "w"))) { - g_message (_("Cannot save palette '%s':\n%s"), - GIMP_DATA (palette)->filename, g_strerror (errno)); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for writing: %s"), + data->filename, g_strerror (errno)); return FALSE; } @@ -509,9 +517,6 @@ gimp_palette_save (GimpData *data) fclose (fp); - if (GIMP_DATA_CLASS (parent_class)->save) - return GIMP_DATA_CLASS (parent_class)->save (data); - return TRUE; } diff --git a/app/core/gimppalette-save.c b/app/core/gimppalette-save.c index acb2d270a6..c86fb2698c 100644 --- a/app/core/gimppalette-save.c +++ b/app/core/gimppalette-save.c @@ -52,7 +52,8 @@ static TempBuf * gimp_palette_get_new_preview (GimpViewable *viewable, gint width, gint height); static void gimp_palette_dirty (GimpData *data); -static gboolean gimp_palette_save (GimpData *data); +static gboolean gimp_palette_save (GimpData *data, + GError **error); static gchar * gimp_palette_get_extension (GimpData *data); static void gimp_palette_entry_free (GimpPaletteEntry *entry); @@ -273,8 +274,9 @@ gimp_palette_get_standard (void) } GimpData * -gimp_palette_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_palette_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpPalette *palette; gchar str[1024]; @@ -286,14 +288,16 @@ gimp_palette_load (const gchar *filename, g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (*filename != '\0', NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); r = g = b = 0; /* Open the requested file */ if (! (fp = fopen (filename, "r"))) { - g_message (_("Failed to open palette file '%s': %s"), - filename, g_strerror (errno)); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); return NULL; } @@ -306,12 +310,16 @@ gimp_palette_load (const gchar *filename, { /* bad magic, but maybe it has \r\n at the end of lines? */ if (!strcmp (str, "GIMP Palette\r")) - g_message (_("Loading palette '%s':\n" - "Corrupt palette: missing magic header\n" - "Does this file need converting from DOS?"), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\n" + "Corrupt palette: missing magic header\n" + "Does this file need converting from DOS?"), + filename); else - g_message (_("Loading palette '%s':\n" - "Corrupt palette: missing magic header"), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\n" + "Corrupt palette: missing magic header"), + filename); fclose (fp); @@ -324,9 +332,9 @@ gimp_palette_load (const gchar *filename, if (! fgets (str, 1024, fp)) { - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -349,9 +357,9 @@ gimp_palette_load (const gchar *filename, if (! fgets (str, 1024, fp)) { - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -370,7 +378,6 @@ gimp_palette_load (const gchar *filename, g_message (_("Loading palette '%s':\n" "Invalid number of columns in line %d."), filename, linenum); - columns = 0; } @@ -378,9 +385,9 @@ gimp_palette_load (const gchar *filename, if (! fgets (str, 1024, fp)) { - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -396,7 +403,6 @@ gimp_palette_load (const gchar *filename, basename = g_path_get_basename (filename); gimp_object_set_name (GIMP_OBJECT (palette), basename); - g_free (basename); } @@ -449,9 +455,9 @@ gimp_palette_load (const gchar *filename, if (feof (fp)) break; - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -475,7 +481,8 @@ gimp_palette_dirty (GimpData *data) } static gboolean -gimp_palette_save (GimpData *data) +gimp_palette_save (GimpData *data, + GError **error) { GimpPalette *palette; GimpPaletteEntry *entry; @@ -485,10 +492,11 @@ gimp_palette_save (GimpData *data) palette = GIMP_PALETTE (data); - if (! (fp = fopen (GIMP_DATA (palette)->filename, "w"))) + if (! (fp = fopen (data->filename, "w"))) { - g_message (_("Cannot save palette '%s':\n%s"), - GIMP_DATA (palette)->filename, g_strerror (errno)); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for writing: %s"), + data->filename, g_strerror (errno)); return FALSE; } @@ -509,9 +517,6 @@ gimp_palette_save (GimpData *data) fclose (fp); - if (GIMP_DATA_CLASS (parent_class)->save) - return GIMP_DATA_CLASS (parent_class)->save (data); - return TRUE; } diff --git a/app/core/gimppalette.c b/app/core/gimppalette.c index acb2d270a6..c86fb2698c 100644 --- a/app/core/gimppalette.c +++ b/app/core/gimppalette.c @@ -52,7 +52,8 @@ static TempBuf * gimp_palette_get_new_preview (GimpViewable *viewable, gint width, gint height); static void gimp_palette_dirty (GimpData *data); -static gboolean gimp_palette_save (GimpData *data); +static gboolean gimp_palette_save (GimpData *data, + GError **error); static gchar * gimp_palette_get_extension (GimpData *data); static void gimp_palette_entry_free (GimpPaletteEntry *entry); @@ -273,8 +274,9 @@ gimp_palette_get_standard (void) } GimpData * -gimp_palette_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_palette_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpPalette *palette; gchar str[1024]; @@ -286,14 +288,16 @@ gimp_palette_load (const gchar *filename, g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (*filename != '\0', NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); r = g = b = 0; /* Open the requested file */ if (! (fp = fopen (filename, "r"))) { - g_message (_("Failed to open palette file '%s': %s"), - filename, g_strerror (errno)); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); return NULL; } @@ -306,12 +310,16 @@ gimp_palette_load (const gchar *filename, { /* bad magic, but maybe it has \r\n at the end of lines? */ if (!strcmp (str, "GIMP Palette\r")) - g_message (_("Loading palette '%s':\n" - "Corrupt palette: missing magic header\n" - "Does this file need converting from DOS?"), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\n" + "Corrupt palette: missing magic header\n" + "Does this file need converting from DOS?"), + filename); else - g_message (_("Loading palette '%s':\n" - "Corrupt palette: missing magic header"), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\n" + "Corrupt palette: missing magic header"), + filename); fclose (fp); @@ -324,9 +332,9 @@ gimp_palette_load (const gchar *filename, if (! fgets (str, 1024, fp)) { - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -349,9 +357,9 @@ gimp_palette_load (const gchar *filename, if (! fgets (str, 1024, fp)) { - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -370,7 +378,6 @@ gimp_palette_load (const gchar *filename, g_message (_("Loading palette '%s':\n" "Invalid number of columns in line %d."), filename, linenum); - columns = 0; } @@ -378,9 +385,9 @@ gimp_palette_load (const gchar *filename, if (! fgets (str, 1024, fp)) { - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -396,7 +403,6 @@ gimp_palette_load (const gchar *filename, basename = g_path_get_basename (filename); gimp_object_set_name (GIMP_OBJECT (palette), basename); - g_free (basename); } @@ -449,9 +455,9 @@ gimp_palette_load (const gchar *filename, if (feof (fp)) break; - g_message (_("Loading palette '%s':\nRead error in line %d."), - filename, linenum); - + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Loading palette '%s':\nRead error in line %d."), + filename, linenum); fclose (fp); g_object_unref (G_OBJECT (palette)); return NULL; @@ -475,7 +481,8 @@ gimp_palette_dirty (GimpData *data) } static gboolean -gimp_palette_save (GimpData *data) +gimp_palette_save (GimpData *data, + GError **error) { GimpPalette *palette; GimpPaletteEntry *entry; @@ -485,10 +492,11 @@ gimp_palette_save (GimpData *data) palette = GIMP_PALETTE (data); - if (! (fp = fopen (GIMP_DATA (palette)->filename, "w"))) + if (! (fp = fopen (data->filename, "w"))) { - g_message (_("Cannot save palette '%s':\n%s"), - GIMP_DATA (palette)->filename, g_strerror (errno)); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for writing: %s"), + data->filename, g_strerror (errno)); return FALSE; } @@ -509,9 +517,6 @@ gimp_palette_save (GimpData *data) fclose (fp); - if (GIMP_DATA_CLASS (parent_class)->save) - return GIMP_DATA_CLASS (parent_class)->save (data); - return TRUE; } diff --git a/app/core/gimppalette.h b/app/core/gimppalette.h index 6df72691c6..9a4d324e3f 100644 --- a/app/core/gimppalette.h +++ b/app/core/gimppalette.h @@ -68,7 +68,8 @@ GimpData * gimp_palette_new (const gchar *name, gboolean stingy_memory_use); GimpData * gimp_palette_get_standard (void); GimpData * gimp_palette_load (const gchar *filename, - gboolean stingy_memory_use); + gboolean stingy_memory_use, + GError **error); GimpPaletteEntry * gimp_palette_add_entry (GimpPalette *palette, const gchar *name, diff --git a/app/core/gimppattern-load.c b/app/core/gimppattern-load.c index 1772370499..c00d00e2be 100644 --- a/app/core/gimppattern-load.c +++ b/app/core/gimppattern-load.c @@ -18,6 +18,7 @@ #include "config.h" +#include #include #include #include @@ -281,8 +282,9 @@ gimp_pattern_get_standard (void) } GimpData * -gimp_pattern_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_pattern_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpPattern *pattern = NULL; gint fd; @@ -291,14 +293,25 @@ gimp_pattern_load (const gchar *filename, gchar *name = NULL; g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); fd = open (filename, O_RDONLY | _O_BINARY); if (fd == -1) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); + return NULL; + } /* Read in the header size */ if (read (fd, &header, sizeof (header)) != sizeof (header)) - goto error; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Could not read %d bytes from '%s': %s"), + sizeof (header), filename, g_strerror (errno)); + goto error; + } /* rearrange the bytes in each unsigned int */ header.header_size = g_ntohl (header.header_size); @@ -312,18 +325,20 @@ gimp_pattern_load (const gchar *filename, if (header.magic_number != GPATTERN_MAGIC || header.version != 1 || header.header_size <= sizeof (header)) { - g_message (_("Unknown pattern format version %d in '%s'."), - header.version, filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Unknown pattern format version %d in '%s'."), + header.version, filename); goto error; } /* Check for supported bit depths */ if (header.bytes != 1 && header.bytes != 3) { - g_message (_("Unsupported pattern depth %d\n" - "in file '%s'.\n" - "GIMP Patterns must be GRAY or RGB.\n"), - header.bytes, filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Unsupported pattern depth %d\n" + "in file '%s'.\n" + "GIMP Patterns must be GRAY or RGB.\n"), + header.bytes, filename); goto error; } @@ -334,7 +349,9 @@ gimp_pattern_load (const gchar *filename, if ((read (fd, name, bn_size)) < bn_size) { - g_message (_("Error in GIMP pattern file '%s'."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Error in GIMP pattern file '%s'."), + filename); goto error; } @@ -358,15 +375,16 @@ gimp_pattern_load (const gchar *filename, header.width * header.height * header.bytes) < header.width * header.height * header.bytes) { - g_message (_("Fatal parsing error: Pattern file '%s' appears truncated."), - filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error: " + "Pattern file '%s' appears truncated."), + filename); goto error; } close (fd); gimp_object_set_name (GIMP_OBJECT (pattern), name); - g_free (name); gimp_data_set_filename (GIMP_DATA (pattern), filename); @@ -375,6 +393,8 @@ gimp_pattern_load (const gchar *filename, if (stingy_memory_use) temp_buf_swap (pattern->mask); + GIMP_DATA (pattern)->dirty = FALSE; + return GIMP_DATA (pattern); error: diff --git a/app/core/gimppattern.c b/app/core/gimppattern.c index 1772370499..c00d00e2be 100644 --- a/app/core/gimppattern.c +++ b/app/core/gimppattern.c @@ -18,6 +18,7 @@ #include "config.h" +#include #include #include #include @@ -281,8 +282,9 @@ gimp_pattern_get_standard (void) } GimpData * -gimp_pattern_load (const gchar *filename, - gboolean stingy_memory_use) +gimp_pattern_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpPattern *pattern = NULL; gint fd; @@ -291,14 +293,25 @@ gimp_pattern_load (const gchar *filename, gchar *name = NULL; g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); fd = open (filename, O_RDONLY | _O_BINARY); if (fd == -1) - return NULL; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, + _("Could not open '%s' for reading: %s"), + filename, g_strerror (errno)); + return NULL; + } /* Read in the header size */ if (read (fd, &header, sizeof (header)) != sizeof (header)) - goto error; + { + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Could not read %d bytes from '%s': %s"), + sizeof (header), filename, g_strerror (errno)); + goto error; + } /* rearrange the bytes in each unsigned int */ header.header_size = g_ntohl (header.header_size); @@ -312,18 +325,20 @@ gimp_pattern_load (const gchar *filename, if (header.magic_number != GPATTERN_MAGIC || header.version != 1 || header.header_size <= sizeof (header)) { - g_message (_("Unknown pattern format version %d in '%s'."), - header.version, filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Unknown pattern format version %d in '%s'."), + header.version, filename); goto error; } /* Check for supported bit depths */ if (header.bytes != 1 && header.bytes != 3) { - g_message (_("Unsupported pattern depth %d\n" - "in file '%s'.\n" - "GIMP Patterns must be GRAY or RGB.\n"), - header.bytes, filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Unsupported pattern depth %d\n" + "in file '%s'.\n" + "GIMP Patterns must be GRAY or RGB.\n"), + header.bytes, filename); goto error; } @@ -334,7 +349,9 @@ gimp_pattern_load (const gchar *filename, if ((read (fd, name, bn_size)) < bn_size) { - g_message (_("Error in GIMP pattern file '%s'."), filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Error in GIMP pattern file '%s'."), + filename); goto error; } @@ -358,15 +375,16 @@ gimp_pattern_load (const gchar *filename, header.width * header.height * header.bytes) < header.width * header.height * header.bytes) { - g_message (_("Fatal parsing error: Pattern file '%s' appears truncated."), - filename); + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Fatal parsing error: " + "Pattern file '%s' appears truncated."), + filename); goto error; } close (fd); gimp_object_set_name (GIMP_OBJECT (pattern), name); - g_free (name); gimp_data_set_filename (GIMP_DATA (pattern), filename); @@ -375,6 +393,8 @@ gimp_pattern_load (const gchar *filename, if (stingy_memory_use) temp_buf_swap (pattern->mask); + GIMP_DATA (pattern)->dirty = FALSE; + return GIMP_DATA (pattern); error: diff --git a/app/core/gimppattern.h b/app/core/gimppattern.h index af513bd3d4..6bc3750ea4 100644 --- a/app/core/gimppattern.h +++ b/app/core/gimppattern.h @@ -51,13 +51,14 @@ struct _GimpPatternClass GType gimp_pattern_get_type (void) G_GNUC_CONST; -GimpData * gimp_pattern_new (const gchar *name, - gboolean stingy_memory_use); +GimpData * gimp_pattern_new (const gchar *name, + gboolean stingy_memory_use); GimpData * gimp_pattern_get_standard (void); -GimpData * gimp_pattern_load (const gchar *filename, - gboolean stingy_memory_use); +GimpData * gimp_pattern_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error); -TempBuf * gimp_pattern_get_mask (const GimpPattern *pattern); +TempBuf * gimp_pattern_get_mask (const GimpPattern *pattern); #endif /* __GIMP_PATTERN_H__ */ diff --git a/app/gui/gradients-commands.c b/app/gui/gradients-commands.c index 4b371a6f2d..9eeadbffbb 100644 --- a/app/gui/gradients-commands.c +++ b/app/gui/gradients-commands.c @@ -150,75 +150,17 @@ static void gradients_save_as_pov_ok_callback (GtkWidget *widget, GimpGradient *gradient) { - GtkFileSelection *filesel; - const gchar *filename; - FILE *file; - GimpGradientSegment *seg; - gchar buf[3][G_ASCII_DTOSTR_BUF_SIZE]; + GtkFileSelection *filesel; + const gchar *filename; + GError *error = NULL; filesel = GTK_FILE_SELECTION (gtk_widget_get_toplevel (widget)); filename = gtk_file_selection_get_filename (filesel); - file = fopen (filename, "wb"); - - if (!file) + if (! gimp_gradient_save_as_pov (gradient, filename, &error)) { - g_message ("Could not open \"%s\"", filename); - } - else - { - fprintf (file, "/* color_map file created by the GIMP */\n"); - fprintf (file, "/* http://www.gimp.org/ */\n"); - - fprintf (file, "color_map {\n"); - - for (seg = gradient->segments; seg; seg = seg->next) - { - /* Left */ - g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->left_color.r); - g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->left_color.g); - g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->left_color.b); - g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", - 1.0 - seg->left_color.a); - - fprintf (file, "\t[%f color rgbt <%s, %s, %s, %s>]\n", - seg->left, - buf[0], buf[1], buf[2], buf[3]); - - /* Middle */ - g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", - (seg->left_color.r + seg->right_color.r) / 2.0); - g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", - (seg->left_color.g + seg->right_color.g) / 2.0); - g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", - (seg->left_color.b + seg->right_color.b) / 2.0); - g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", - 1.0 - (seg->left_color.a + seg->right_color.a) / 2.0); - - fprintf (file, "\t[%f color rgbt <%s, %s, %s, %s>]\n", - seg->middle, - buf[0], buf[1], buf[2], buf[3]); - - /* Right */ - g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->right_color.r); - g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->right_color.g); - g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", - seg->right_color.b); - g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", - 1.0 - seg->right_color.a); - - fprintf (file, "\t[%f color rgbt <%s, %s, %s, %s>]\n", - seg->right, - buf[0], buf[1], buf[2], buf[3]); - } - - fprintf (file, "} /* color_map */\n"); - fclose (file); + g_message (error->message); + g_clear_error (&error); } gtk_widget_destroy (GTK_WIDGET (filesel)); diff --git a/app/widgets/gimpdatafactoryview.c b/app/widgets/gimpdatafactoryview.c index afdb6b6e7f..cfcdfa5de8 100644 --- a/app/widgets/gimpdatafactoryview.c +++ b/app/widgets/gimpdatafactoryview.c @@ -21,9 +21,6 @@ #include "config.h" -#include -#include - #include #include "libgimpmath/gimpmath.h" @@ -286,45 +283,12 @@ gimp_data_factory_view_duplicate_clicked (GtkWidget *widget, if (data && gimp_container_have (view->factory->container, GIMP_OBJECT (data))) { - GimpBaseConfig *base_config; - GimpData *new_data; + GimpData *new_data; - base_config = GIMP_BASE_CONFIG (view->factory->gimp->config); - - new_data = gimp_data_duplicate (data, base_config->stingy_memory_use); + new_data = gimp_data_factory_data_duplicate (view->factory, data); if (new_data) { - const gchar *name; - gchar *ext; - gint copy_len; - gint number; - gchar *new_name; - - name = gimp_object_get_name (GIMP_OBJECT (data)); - - ext = strrchr (name, '#'); - copy_len = strlen (_("copy")); - - if ((strlen (name) >= copy_len && - strcmp (&name[strlen (name) - copy_len], _("copy")) == 0) || - (ext && (number = atoi (ext + 1)) > 0 && - ((gint) (log10 (number) + 1)) == strlen (ext + 1))) - { - /* don't have redundant "copy"s */ - new_name = g_strdup (name); - } - else - { - new_name = g_strdup_printf (_("%s copy"), name); - } - - gimp_object_set_name (GIMP_OBJECT (new_data), new_name); - - g_free (new_name); - - gimp_container_add (view->factory->container, GIMP_OBJECT (new_data)); - gimp_context_set_by_type (GIMP_CONTAINER_EDITOR (view)->view->context, view->factory->container->children_type, GIMP_OBJECT (new_data));