added "gboolean writable" to the GimpDataFactoryLoaderEntry struct. Return

2004-07-26  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpdatafactory.h: added "gboolean writable" to the
	GimpDataFactoryLoaderEntry struct. Return a GList* instead of
	GimpData* from GimpDataLoadFunc so it's possible to load more than
	one data object from one file.

	* app/core/gimpdatafactory.c (gimp_data_factory_load_data):
	changed accordingly: add all items of the returned lists to the
	data factory. Make the data object writable only if it's in the
	writable path *and* its loader entry says it's a writable format
	*and* the returned list contains exactly one element.

	* app/core/gimp.c (gimp_real_initialize): declare all loader
	entries as writable where we have code to read and write exactly
	one object per file; all others are not writable.

	* app/core/gimpbrush.[ch]
	* app/core/gimpbrushgenerated.[ch]
	* app/core/gimpbrushpipe.[ch]
	* app/core/gimpgradient-load.[ch]
	* app/core/gimppalette.[ch]
	* app/core/gimppattern.[ch] (all load functions): return a list
	containing the loaded object instead of the object itself.
This commit is contained in:
Michael Natterer 2004-07-26 19:00:22 +00:00 committed by Michael Natterer
parent 74a98a6640
commit 638f2b3a9c
23 changed files with 103 additions and 67 deletions

View File

@ -1,3 +1,28 @@
2004-07-26 Michael Natterer <mitch@gimp.org>
* app/core/gimpdatafactory.h: added "gboolean writable" to the
GimpDataFactoryLoaderEntry struct. Return a GList* instead of
GimpData* from GimpDataLoadFunc so it's possible to load more than
one data object from one file.
* app/core/gimpdatafactory.c (gimp_data_factory_load_data):
changed accordingly: add all items of the returned lists to the
data factory. Make the data object writable only if it's in the
writable path *and* its loader entry says it's a writable format
*and* the returned list contains exactly one element.
* app/core/gimp.c (gimp_real_initialize): declare all loader
entries as writable where we have code to read and write exactly
one object per file; all others are not writable.
* app/core/gimpbrush.[ch]
* app/core/gimpbrushgenerated.[ch]
* app/core/gimpbrushpipe.[ch]
* app/core/gimpgradient-load.[ch]
* app/core/gimppalette.[ch]
* app/core/gimppattern.[ch] (all load functions): return a list
containing the loaded object instead of the object itself.
2004-07-26 Sven Neumann <sven@gimp.org>
* libgimpwidgets/Makefile.am

View File

@ -529,29 +529,29 @@ gimp_real_initialize (Gimp *gimp,
static const GimpDataFactoryLoaderEntry brush_loader_entries[] =
{
{ gimp_brush_load, GIMP_BRUSH_FILE_EXTENSION },
{ gimp_brush_load, GIMP_BRUSH_PIXMAP_FILE_EXTENSION },
{ gimp_brush_generated_load, GIMP_BRUSH_GENERATED_FILE_EXTENSION },
{ gimp_brush_pipe_load, GIMP_BRUSH_PIPE_FILE_EXTENSION }
{ gimp_brush_load, GIMP_BRUSH_FILE_EXTENSION, FALSE },
{ gimp_brush_load, GIMP_BRUSH_PIXMAP_FILE_EXTENSION, FALSE },
{ gimp_brush_generated_load, GIMP_BRUSH_GENERATED_FILE_EXTENSION, TRUE },
{ gimp_brush_pipe_load, GIMP_BRUSH_PIPE_FILE_EXTENSION, FALSE }
};
static const GimpDataFactoryLoaderEntry pattern_loader_entries[] =
{
{ gimp_pattern_load, GIMP_PATTERN_FILE_EXTENSION },
{ gimp_pattern_load_pixbuf, NULL }
{ gimp_pattern_load, GIMP_PATTERN_FILE_EXTENSION, FALSE },
{ gimp_pattern_load_pixbuf, NULL, FALSE }
};
static const GimpDataFactoryLoaderEntry gradient_loader_entries[] =
{
{ gimp_gradient_load, GIMP_GRADIENT_FILE_EXTENSION },
{ gimp_gradient_load_svg, GIMP_GRADIENT_SVG_FILE_EXTENSION },
{ gimp_gradient_load, NULL /* legacy loader */ }
{ gimp_gradient_load, GIMP_GRADIENT_FILE_EXTENSION, TRUE },
{ gimp_gradient_load_svg, GIMP_GRADIENT_SVG_FILE_EXTENSION, FALSE },
{ gimp_gradient_load, NULL /* legacy loader */, TRUE }
};
static const GimpDataFactoryLoaderEntry palette_loader_entries[] =
{
{ gimp_palette_load, GIMP_PALETTE_FILE_EXTENSION },
{ gimp_palette_load, NULL /* legacy loader */ }
{ gimp_palette_load, GIMP_PALETTE_FILE_EXTENSION, TRUE },
{ gimp_palette_load, NULL /* legacy loader */, TRUE }
};
if (gimp->be_verbose)

View File

@ -372,7 +372,7 @@ gimp_brush_get_standard (void)
return standard_brush;
}
GimpData *
GList *
gimp_brush_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -409,7 +409,7 @@ gimp_brush_load (const gchar *filename,
temp_buf_swap (brush->pixmap);
}
return GIMP_DATA (brush);
return g_list_prepend (NULL, brush);
}
GimpBrush *

View File

@ -372,7 +372,7 @@ gimp_brush_get_standard (void)
return standard_brush;
}
GimpData *
GList *
gimp_brush_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -409,7 +409,7 @@ gimp_brush_load (const gchar *filename,
temp_buf_swap (brush->pixmap);
}
return GIMP_DATA (brush);
return g_list_prepend (NULL, brush);
}
GimpBrush *

View File

@ -71,7 +71,7 @@ GType gimp_brush_get_type (void) G_GNUC_CONST;
GimpData * gimp_brush_new (const gchar *name,
gboolean stingy_memory_use);
GimpData * gimp_brush_get_standard (void);
GimpData * gimp_brush_load (const gchar *filename,
GList * gimp_brush_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error);

View File

@ -450,7 +450,7 @@ gimp_brush_generated_new (const gchar *name,
return GIMP_DATA (brush);
}
GimpData *
GList *
gimp_brush_generated_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -567,7 +567,7 @@ gimp_brush_generated_load (const gchar *filename,
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
return GIMP_DATA (brush);
return g_list_prepend (NULL, brush);
failed:

View File

@ -450,7 +450,7 @@ gimp_brush_generated_new (const gchar *name,
return GIMP_DATA (brush);
}
GimpData *
GList *
gimp_brush_generated_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -567,7 +567,7 @@ gimp_brush_generated_load (const gchar *filename,
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
return GIMP_DATA (brush);
return g_list_prepend (NULL, brush);
failed:

View File

@ -450,7 +450,7 @@ gimp_brush_generated_new (const gchar *name,
return GIMP_DATA (brush);
}
GimpData *
GList *
gimp_brush_generated_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -567,7 +567,7 @@ gimp_brush_generated_load (const gchar *filename,
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
return GIMP_DATA (brush);
return g_list_prepend (NULL, brush);
failed:

View File

@ -62,7 +62,7 @@ GimpData * gimp_brush_generated_new (const gchar *name,
gfloat aspect_ratio,
gfloat angle,
gboolean stingy_memory_use);
GimpData * gimp_brush_generated_load (const gchar *file_name,
GList * gimp_brush_generated_load (const gchar *file_name,
gboolean stingy_memory_use,
GError **error);

View File

@ -317,7 +317,7 @@ gimp_brush_pipe_want_null_motion (GimpBrush *brush,
return TRUE;
}
GimpData *
GList *
gimp_brush_pipe_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -505,5 +505,5 @@ gimp_brush_pipe_load (const gchar *filename,
GIMP_BRUSH (pipe)->mask = pipe->current->mask;
GIMP_BRUSH (pipe)->pixmap = pipe->current->pixmap;
return GIMP_DATA (pipe);
return g_list_prepend (NULL, pipe);
}

View File

@ -317,7 +317,7 @@ gimp_brush_pipe_want_null_motion (GimpBrush *brush,
return TRUE;
}
GimpData *
GList *
gimp_brush_pipe_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -505,5 +505,5 @@ gimp_brush_pipe_load (const gchar *filename,
GIMP_BRUSH (pipe)->mask = pipe->current->mask;
GIMP_BRUSH (pipe)->pixmap = pipe->current->pixmap;
return GIMP_DATA (pipe);
return g_list_prepend (NULL, pipe);
}

View File

@ -73,11 +73,11 @@ struct _GimpBrushPipeClass
};
GType gimp_brush_pipe_get_type (void) G_GNUC_CONST;
GType gimp_brush_pipe_get_type (void) G_GNUC_CONST;
GimpData * gimp_brush_pipe_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
GList * gimp_brush_pipe_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
#endif /* __GIMP_BRUSH_PIPE_H__ */

View File

@ -588,17 +588,17 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
insert:
{
GimpBaseConfig *base_config;
GimpData *data;
GList *data_list;
GError *error = NULL;
base_config = GIMP_BASE_CONFIG (factory->gimp->config);
data = (GimpData *)
data_list =
(* factory->loader_entries[i].load_func) (file_data->filename,
base_config->stingy_memory_use,
&error);
if (! data)
if (! data_list)
{
g_message (_("Warning: Failed to load data:\n\n%s"),
error->message);
@ -607,19 +607,29 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
else
{
GList *writable_list;
GList *list;
gboolean writable = FALSE;
writable_list = g_object_get_data (G_OBJECT (factory),
WRITABLE_PATH_KEY);
writable = (g_list_find_custom (writable_list, file_data->dirname,
writable = (factory->loader_entries[i].writable &&
g_list_length (data_list) == 1 &&
g_list_find_custom (writable_list, file_data->dirname,
(GCompareFunc) strcmp) != NULL);
gimp_data_set_filename (data, file_data->filename, writable);
data->dirty = FALSE;
for (list = data_list; list; list = g_list_next (list))
{
GimpData *data = list->data;
gimp_container_add (factory->container, GIMP_OBJECT (data));
g_object_unref (data);
gimp_data_set_filename (data, file_data->filename, writable);
data->dirty = FALSE;
gimp_container_add (factory->container, GIMP_OBJECT (data));
g_object_unref (data);
}
g_list_free (data_list);
}
}
}

View File

@ -28,7 +28,7 @@
typedef GimpData * (* GimpDataNewFunc) (const gchar *name,
gboolean stingy_memory_use);
typedef GimpData * (* GimpDataLoadFunc) (const gchar *filename,
typedef GList * (* GimpDataLoadFunc) (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
typedef GimpData * (* GimpDataGetStandardFunc) (void);
@ -40,6 +40,7 @@ struct _GimpDataFactoryLoaderEntry
{
GimpDataLoadFunc load_func;
const gchar *extension;
gboolean writable;
};

View File

@ -38,7 +38,7 @@
#include "gimp-intl.h"
GimpData *
GList *
gimp_gradient_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -178,7 +178,7 @@ gimp_gradient_load (const gchar *filename,
fclose (file);
return GIMP_DATA (gradient);
return g_list_prepend (NULL, gradient);
}
@ -236,7 +236,7 @@ static const GMarkupParser markup_parser =
};
GimpData *
GList *
gimp_gradient_load_svg (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -292,7 +292,7 @@ gimp_gradient_load_svg (const gchar *filename,
g_list_foreach (parser.stops, (GFunc) g_free, NULL);
g_list_free (parser.stops);
return data;
return g_list_prepend (NULL, data);
}
static void

View File

@ -20,12 +20,12 @@
#define __GIMP_GRADIENT_LOAD_H__
GimpData * gimp_gradient_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
GimpData * gimp_gradient_load_svg (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
GList * gimp_gradient_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
GList * gimp_gradient_load_svg (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
#endif /* __GIMP_GRADIENT_LOAD_H__ */

View File

@ -337,7 +337,7 @@ gimp_palette_get_standard (void)
return standard_palette;
}
GimpData *
GList *
gimp_palette_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -552,7 +552,7 @@ gimp_palette_load (const gchar *filename,
palette->colors = g_list_reverse (palette->colors);
return GIMP_DATA (palette);
return g_list_prepend (NULL, palette);
}
static gboolean

View File

@ -337,7 +337,7 @@ gimp_palette_get_standard (void)
return standard_palette;
}
GimpData *
GList *
gimp_palette_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -552,7 +552,7 @@ gimp_palette_load (const gchar *filename,
palette->colors = g_list_reverse (palette->colors);
return GIMP_DATA (palette);
return g_list_prepend (NULL, palette);
}
static gboolean

View File

@ -337,7 +337,7 @@ gimp_palette_get_standard (void)
return standard_palette;
}
GimpData *
GList *
gimp_palette_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -552,7 +552,7 @@ gimp_palette_load (const gchar *filename,
palette->colors = g_list_reverse (palette->colors);
return GIMP_DATA (palette);
return g_list_prepend (NULL, palette);
}
static gboolean

View File

@ -67,7 +67,7 @@ GType gimp_palette_get_type (void) G_GNUC_CONST;
GimpData * gimp_palette_new (const gchar *name,
gboolean stingy_memory_use);
GimpData * gimp_palette_get_standard (void);
GimpData * gimp_palette_load (const gchar *filename,
GList * gimp_palette_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error);

View File

@ -306,7 +306,7 @@ gimp_pattern_get_standard (void)
return standard_pattern;
}
GimpData *
GList *
gimp_pattern_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -426,7 +426,7 @@ gimp_pattern_load (const gchar *filename,
if (stingy_memory_use)
temp_buf_swap (pattern->mask);
return GIMP_DATA (pattern);
return g_list_prepend (NULL, pattern);
error:
if (pattern)
@ -437,7 +437,7 @@ gimp_pattern_load (const gchar *filename,
return NULL;
}
GimpData *
GList *
gimp_pattern_load_pixbuf (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -503,7 +503,7 @@ gimp_pattern_load_pixbuf (const gchar *filename,
if (stingy_memory_use)
temp_buf_swap (pattern->mask);
return GIMP_DATA (pattern);
return g_list_prepend (NULL, pattern);
}
TempBuf *

View File

@ -306,7 +306,7 @@ gimp_pattern_get_standard (void)
return standard_pattern;
}
GimpData *
GList *
gimp_pattern_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -426,7 +426,7 @@ gimp_pattern_load (const gchar *filename,
if (stingy_memory_use)
temp_buf_swap (pattern->mask);
return GIMP_DATA (pattern);
return g_list_prepend (NULL, pattern);
error:
if (pattern)
@ -437,7 +437,7 @@ gimp_pattern_load (const gchar *filename,
return NULL;
}
GimpData *
GList *
gimp_pattern_load_pixbuf (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
@ -503,7 +503,7 @@ gimp_pattern_load_pixbuf (const gchar *filename,
if (stingy_memory_use)
temp_buf_swap (pattern->mask);
return GIMP_DATA (pattern);
return g_list_prepend (NULL, pattern);
}
TempBuf *

View File

@ -54,10 +54,10 @@ GType gimp_pattern_get_type (void) G_GNUC_CONST;
GimpData * gimp_pattern_new (const gchar *name,
gboolean stingy_memory_use);
GimpData * gimp_pattern_get_standard (void);
GimpData * gimp_pattern_load (const gchar *filename,
GList * gimp_pattern_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
GimpData * gimp_pattern_load_pixbuf (const gchar *filename,
GList * gimp_pattern_load_pixbuf (const gchar *filename,
gboolean stingy_memory_use,
GError **error);