app: change the GimpData loading API from filename to GFile

This commit is contained in:
Michael Natterer 2014-07-01 02:30:22 +02:00
parent 7be12ec523
commit 113617f526
18 changed files with 263 additions and 194 deletions

View File

@ -89,22 +89,22 @@ struct _AbrSampledBrushHeader
static GList * gimp_brush_load_abr_v12 (FILE *file,
AbrHeader *abr_hdr,
const gchar *filename,
const gchar *path,
GError **error);
static GList * gimp_brush_load_abr_v6 (FILE *file,
AbrHeader *abr_hdr,
const gchar *filename,
const gchar *path,
GError **error);
static GimpBrush * gimp_brush_load_abr_brush_v12 (FILE *file,
AbrHeader *abr_hdr,
gint index,
const gchar *filename,
const gchar *path,
GError **error);
static GimpBrush * gimp_brush_load_abr_brush_v6 (FILE *file,
AbrHeader *abr_hdr,
gint32 max_offset,
gint index,
const gchar *filename,
const gchar *path,
GError **error);
static gchar abr_read_char (FILE *file);
@ -112,7 +112,7 @@ static gint16 abr_read_short (FILE *file);
static gint32 abr_read_long (FILE *file);
static gchar * abr_read_ucs2_text (FILE *file);
static gboolean abr_supported (AbrHeader *abr_hdr,
const gchar *filename,
const gchar *path,
GError **error);
static gboolean abr_reach_8bim_section (FILE *abr,
const gchar *name);
@ -125,28 +125,34 @@ static gint32 abr_rle_decode (FILE *file,
GList *
gimp_brush_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
GimpBrush *brush;
gchar *path;
gint fd;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
path = g_file_get_path (file);
g_return_val_if_fail (g_path_is_absolute (path), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
fd = g_open (filename, O_RDONLY | _O_BINARY, 0);
fd = g_open (path, O_RDONLY | _O_BINARY, 0);
if (fd == -1)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_filename_to_utf8 (path), g_strerror (errno));
g_free (path);
return NULL;
}
brush = gimp_brush_load_brush (context, fd, filename, error);
brush = gimp_brush_load_brush (context, fd, path, error);
close (fd);
g_free (path);
if (! brush)
return NULL;
@ -157,7 +163,7 @@ gimp_brush_load (GimpContext *context,
GimpBrush *
gimp_brush_load_brush (GimpContext *context,
gint fd,
const gchar *filename,
const gchar *path,
GError **error)
{
GimpBrush *brush;
@ -169,7 +175,7 @@ gimp_brush_load_brush (GimpContext *context,
gssize i, size;
gboolean success = TRUE;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (fd != -1, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@ -181,7 +187,7 @@ gimp_brush_load_brush (GimpContext *context,
"Could not read %d bytes from '%s': %s",
(gint) sizeof (header)),
(gint) sizeof (header),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_filename_to_utf8 (path), g_strerror (errno));
return NULL;
}
@ -201,7 +207,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Width = 0."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
return NULL;
}
@ -210,7 +216,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Height = 0."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
return NULL;
}
@ -219,7 +225,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Bytes = 0."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
return NULL;
}
@ -243,7 +249,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Unknown depth %d."),
gimp_filename_to_utf8 (filename), header.bytes);
gimp_filename_to_utf8 (path), header.bytes);
return NULL;
}
/* fallthrough */
@ -256,7 +262,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Unknown version %d."),
gimp_filename_to_utf8 (filename), header.version);
gimp_filename_to_utf8 (path), header.version);
return NULL;
}
@ -272,14 +278,14 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"File appears truncated."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
g_free (name);
return NULL;
}
utf8 = gimp_any_to_utf8 (name, -1,
_("Invalid UTF-8 string in brush file '%s'."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
g_free (name);
name = utf8;
}
@ -357,7 +363,7 @@ gimp_brush_load_brush (GimpContext *context,
"GIMP brushes must be GRAY or RGBA.\n"
"This might be an obsolete GIMP brush file, try "
"loading it as image and save it again."),
gimp_filename_to_utf8 (filename), header.bytes);
gimp_filename_to_utf8 (path), header.bytes);
return NULL;
break;
@ -400,7 +406,7 @@ gimp_brush_load_brush (GimpContext *context,
_("Fatal parse error in brush file '%s': "
"Unsupported brush depth %d\n"
"GIMP brushes must be GRAY or RGBA."),
gimp_filename_to_utf8 (filename), header.bytes);
gimp_filename_to_utf8 (path), header.bytes);
return NULL;
}
@ -410,7 +416,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"File appears truncated."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
return NULL;
}
@ -425,53 +431,59 @@ gimp_brush_load_brush (GimpContext *context,
GList *
gimp_brush_load_abr (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
FILE *file;
gchar *path;
FILE *f;
AbrHeader abr_hdr;
GList *brush_list = NULL;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
path = g_file_get_path (file);
g_return_val_if_fail (g_path_is_absolute (path), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
file = g_fopen (filename, "rb");
if (! file)
f = g_fopen (path, "rb");
if (! f)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_filename_to_utf8 (path), g_strerror (errno));
g_free (path);
return NULL;
}
abr_hdr.version = abr_read_short (file);
abr_hdr.count = abr_read_short (file); /* sub-version for ABR v6 */
abr_hdr.version = abr_read_short (f);
abr_hdr.count = abr_read_short (f); /* sub-version for ABR v6 */
if (abr_supported (&abr_hdr, filename, error))
if (abr_supported (&abr_hdr, path, error))
{
switch (abr_hdr.version)
{
case 1:
case 2:
brush_list = gimp_brush_load_abr_v12 (file, &abr_hdr,
filename, error);
brush_list = gimp_brush_load_abr_v12 (f, &abr_hdr,
path, error);
break;
case 6:
brush_list = gimp_brush_load_abr_v6 (file, &abr_hdr,
filename, error);
brush_list = gimp_brush_load_abr_v6 (f, &abr_hdr,
path, error);
}
}
fclose (file);
fclose (f);
if (! brush_list && (error && ! *error))
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"unable to decode abr format version %d."),
gimp_filename_to_utf8 (filename), abr_hdr.version);
gimp_filename_to_utf8 (path), abr_hdr.version);
g_free (path);
return g_list_reverse (brush_list);
}
@ -482,7 +494,7 @@ gimp_brush_load_abr (GimpContext *context,
static GList *
gimp_brush_load_abr_v12 (FILE *file,
AbrHeader *abr_hdr,
const gchar *filename,
const gchar *path,
GError **error)
{
GList *brush_list = NULL;
@ -494,7 +506,7 @@ gimp_brush_load_abr_v12 (FILE *file,
GError *my_error = NULL;
brush = gimp_brush_load_abr_brush_v12 (file, abr_hdr, i,
filename, &my_error);
path, &my_error);
/* a NULL brush without an error means an unsupported brush
* type was encountered, silently skip it and try the next one
@ -517,7 +529,7 @@ gimp_brush_load_abr_v12 (FILE *file,
static GList *
gimp_brush_load_abr_v6 (FILE *file,
AbrHeader *abr_hdr,
const gchar *filename,
const gchar *path,
GError **error)
{
GList *brush_list = NULL;
@ -537,7 +549,7 @@ gimp_brush_load_abr_v6 (FILE *file,
GError *my_error = NULL;
brush = gimp_brush_load_abr_brush_v6 (file, abr_hdr, sample_section_end,
i, filename, &my_error);
i, path, &my_error);
/* a NULL brush without an error means an unsupported brush
* type was encountered, silently skip it and try the next one
@ -563,13 +575,13 @@ static GimpBrush *
gimp_brush_load_abr_brush_v12 (FILE *file,
AbrHeader *abr_hdr,
gint index,
const gchar *filename,
const gchar *path,
GError **error)
{
GimpBrush *brush = NULL;
AbrBrushHeader abr_brush_hdr;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
abr_brush_hdr.type = abr_read_short (file);
@ -638,11 +650,11 @@ gimp_brush_load_abr_brush_v12 (FILE *file,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Wide brushes are not supported."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
return NULL;
}
tmp = g_filename_display_basename (filename);
tmp = g_filename_display_basename (path);
if (! sample_name)
{
/* build name from filename and index */
@ -703,7 +715,7 @@ gimp_brush_load_abr_brush_v6 (FILE *file,
AbrHeader *abr_hdr,
gint32 max_offset,
gint index,
const gchar *filename,
const gchar *path,
GError **error)
{
GimpBrush *brush = NULL;
@ -745,7 +757,7 @@ gimp_brush_load_abr_brush_v6 (FILE *file,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"File appears truncated."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
return NULL;
}
@ -760,7 +772,7 @@ gimp_brush_load_abr_brush_v6 (FILE *file,
height = bottom - top;
size = width * (depth >> 3) * height;
tmp = g_filename_display_basename (filename);
tmp = g_filename_display_basename (path);
name = g_strdup_printf ("%s-%03d", tmp, index);
g_free (tmp);
@ -854,7 +866,7 @@ abr_read_ucs2_text (FILE *file)
static gboolean
abr_supported (AbrHeader *abr_hdr,
const gchar *filename,
const gchar *path,
GError **error)
{
switch (abr_hdr->version)
@ -873,7 +885,7 @@ abr_supported (AbrHeader *abr_hdr,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"unable to decode abr format version %d."),
gimp_filename_to_utf8 (filename),
gimp_filename_to_utf8 (path),
/* horrid subversion display, but better than
* having yet another translatable string for

View File

@ -26,15 +26,15 @@
GList * gimp_brush_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);
GimpBrush * gimp_brush_load_brush (GimpContext *context,
gint fd,
const gchar *filename,
const gchar *path,
GError **error);
GList * gimp_brush_load_abr (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);

View File

@ -43,11 +43,12 @@
GList *
gimp_brush_generated_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
GimpBrush *brush;
FILE *file;
gchar *path;
FILE *f;
gchar string[256];
gint linenum;
gchar *name = NULL;
@ -60,24 +61,27 @@ gimp_brush_generated_load (GimpContext *context,
gdouble aspect_ratio;
gdouble angle;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
path = g_file_get_path (file);
g_return_val_if_fail (g_path_is_absolute (path), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
file = g_fopen (filename, "rb");
if (! file)
f = g_fopen (path, "rb");
if (! f)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_filename_to_utf8 (path), g_strerror (errno));
g_free (path);
return NULL;
}
/* make sure the file we are reading is the right type */
errno = 0;
linenum = 1;
if (! fgets (string, sizeof (string), file))
if (! fgets (string, sizeof (string), f))
goto failed;
if (! g_str_has_prefix (string, "GIMP-VBR"))
@ -85,14 +89,14 @@ gimp_brush_generated_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Not a GIMP brush file."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
goto failed;
}
/* make sure we are reading a compatible version */
errno = 0;
linenum++;
if (! fgets (string, sizeof (string), file))
if (! fgets (string, sizeof (string), f))
goto failed;
if (! g_str_has_prefix (string, "1.0"))
@ -102,7 +106,7 @@ gimp_brush_generated_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Unknown GIMP brush version in line %d."),
gimp_filename_to_utf8 (filename), linenum);
gimp_filename_to_utf8 (path), linenum);
goto failed;
}
else
@ -114,7 +118,7 @@ gimp_brush_generated_load (GimpContext *context,
/* read name */
errno = 0;
linenum++;
if (! fgets (string, sizeof (string), file))
if (! fgets (string, sizeof (string), f))
goto failed;
g_strstrip (string);
@ -125,7 +129,7 @@ gimp_brush_generated_load (GimpContext *context,
name = gimp_any_to_utf8 (string, -1,
_("Invalid UTF-8 string in brush file '%s'."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
if (have_shape)
{
@ -137,7 +141,7 @@ gimp_brush_generated_load (GimpContext *context,
/* read shape */
errno = 0;
linenum++;
if (! fgets (string, sizeof (string), file))
if (! fgets (string, sizeof (string), f))
goto failed;
g_strstrip (string);
@ -148,7 +152,7 @@ gimp_brush_generated_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Unknown GIMP brush shape in line %d."),
gimp_filename_to_utf8 (filename), linenum);
gimp_filename_to_utf8 (path), linenum);
goto failed;
}
@ -158,14 +162,14 @@ gimp_brush_generated_load (GimpContext *context,
/* read brush spacing */
errno = 0;
linenum++;
if (! fgets (string, sizeof (string), file))
if (! fgets (string, sizeof (string), f))
goto failed;
spacing = g_ascii_strtod (string, NULL);
/* read brush radius */
errno = 0;
linenum++;
if (! fgets (string, sizeof (string), file))
if (! fgets (string, sizeof (string), f))
goto failed;
radius = g_ascii_strtod (string, NULL);
@ -174,7 +178,7 @@ gimp_brush_generated_load (GimpContext *context,
/* read number of spikes */
errno = 0;
linenum++;
if (! fgets (string, sizeof (string), file))
if (! fgets (string, sizeof (string), f))
goto failed;
spikes = CLAMP (atoi (string), 2, 20);
}
@ -182,25 +186,25 @@ gimp_brush_generated_load (GimpContext *context,
/* read brush hardness */
errno = 0;
linenum++;
if (! fgets (string, sizeof (string), file))
if (! fgets (string, sizeof (string), f))
goto failed;
hardness = g_ascii_strtod (string, NULL);
/* read brush aspect_ratio */
errno = 0;
linenum++;
if (! fgets (string, sizeof (string), file))
if (! fgets (string, sizeof (string), f))
goto failed;
aspect_ratio = g_ascii_strtod (string, NULL);
/* read brush angle */
errno = 0;
linenum++;
if (! fgets (string, sizeof (string), file))
if (! fgets (string, sizeof (string), f))
goto failed;
angle = g_ascii_strtod (string, NULL);
fclose (file);
fclose (f);
brush = GIMP_BRUSH (gimp_brush_generated_new (name, shape, radius, spikes,
hardness, aspect_ratio, angle));
@ -208,11 +212,13 @@ gimp_brush_generated_load (GimpContext *context,
brush->spacing = spacing;
g_free (path);
return g_list_prepend (NULL, brush);
failed:
fclose (file);
fclose (f);
if (name)
g_free (name);
@ -228,10 +234,12 @@ gimp_brush_generated_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Error while reading brush file '%s': %s"),
gimp_filename_to_utf8 (filename), msg);
gimp_filename_to_utf8 (path), msg);
g_free (msg);
}
g_free (path);
return NULL;
}

View File

@ -25,7 +25,7 @@
GList * gimp_brush_generated_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);

View File

@ -55,7 +55,7 @@
GList *
gimp_brush_pipe_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
GimpBrushPipe *pipe = NULL;
@ -66,19 +66,23 @@ gimp_brush_pipe_load (GimpContext *context,
gchar *paramstring;
GString *buffer;
gchar c;
gchar *path;
gint fd;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
path = g_file_get_path (file);
g_return_val_if_fail (g_path_is_absolute (path), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
fd = g_open (filename, O_RDONLY | _O_BINARY, 0);
fd = g_open (path, O_RDONLY | _O_BINARY, 0);
if (fd == -1)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_filename_to_utf8 (path), g_strerror (errno));
g_free (path);
return NULL;
}
@ -94,7 +98,7 @@ gimp_brush_pipe_load (GimpContext *context,
gchar *utf8 =
gimp_any_to_utf8 (buffer->str, buffer->len,
_("Invalid UTF-8 string in brush file '%s'."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
pipe = g_object_new (GIMP_TYPE_BRUSH_PIPE,
"name", utf8,
@ -111,8 +115,9 @@ gimp_brush_pipe_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"File is corrupt."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
close (fd);
g_free (path);
return NULL;
}
@ -131,8 +136,9 @@ gimp_brush_pipe_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"File is corrupt."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
close (fd);
g_free (path);
g_object_unref (pipe);
g_string_free (buffer, TRUE);
return NULL;
@ -212,7 +218,7 @@ gimp_brush_pipe_load (GimpContext *context,
GError *my_error = NULL;
pipe->brushes[pipe->n_brushes] = gimp_brush_load_brush (context,
fd, filename,
fd, path,
&my_error);
if (pipe->brushes[pipe->n_brushes])
@ -224,6 +230,7 @@ gimp_brush_pipe_load (GimpContext *context,
{
g_propagate_error (error, my_error);
close (fd);
g_free (path);
g_object_unref (pipe);
return NULL;
}
@ -243,5 +250,7 @@ gimp_brush_pipe_load (GimpContext *context,
GIMP_BRUSH (pipe)->mask = pipe->current->mask;
GIMP_BRUSH (pipe)->pixmap = pipe->current->pixmap;
g_free (path);
return g_list_prepend (NULL, pipe);
}

View File

@ -24,7 +24,7 @@
GList * gimp_brush_pipe_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);

View File

@ -844,6 +844,7 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
GimpDataFactory *factory = context->factory;
GHashTable *cache = context->cache;
const GimpDataFactoryLoaderEntry *loader = NULL;
GFile *file = NULL;
GError *error = NULL;
GList *data_list;
gint i;
@ -865,13 +866,11 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
return;
insert:
file = g_file_new_for_path (file_data->filename);
if (cache)
{
GFile *file = g_file_new_for_path (file_data->filename);
GList *cached_data;
cached_data = g_hash_table_lookup (cache, file);
g_object_unref (file);
GList *cached_data = g_hash_table_lookup (cache, file);
if (cached_data &&
gimp_data_get_mtime (cached_data->data) != 0 &&
@ -882,11 +881,13 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
for (list = cached_data; list; list = g_list_next (list))
gimp_container_add (factory->priv->container, list->data);
g_object_unref (file);
return;
}
}
data_list = loader->load_func (context->context, file_data->filename, &error);
data_list = loader->load_func (context->context, file, &error);
if (G_LIKELY (data_list))
{
@ -916,13 +917,9 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
for (list = data_list; list; list = g_list_next (list))
{
GimpData *data = list->data;
GFile *file = g_file_new_for_path (file_data->filename);
gimp_data_set_file (data, file, writable, deletable);
gimp_data_set_mtime (data, file_data->mtime);
g_object_unref (file);
gimp_data_clean (data);
if (obsolete)
@ -944,6 +941,8 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
g_list_free (data_list);
}
g_object_unref (file);
/* not else { ... } because loader->load_func() can return a list
* of data objects *and* an error message if loading failed after
* something was already loaded

View File

@ -28,7 +28,7 @@
typedef GimpData * (* GimpDataNewFunc) (GimpContext *context,
const gchar *name);
typedef GList * (* GimpDataLoadFunc) (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);
typedef GimpData * (* GimpDataGetStandardFunc) (GimpContext *context);

View File

@ -30,20 +30,19 @@
GList *
gimp_dynamics_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
GimpDynamics *dynamics;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
dynamics = g_object_new (GIMP_TYPE_DYNAMICS, NULL);
if (gimp_config_deserialize_file (GIMP_CONFIG (dynamics),
filename,
NULL, error))
if (gimp_config_deserialize_gfile (GIMP_CONFIG (dynamics),
file,
NULL, error))
{
return g_list_prepend (NULL, dynamics);
}

View File

@ -23,7 +23,7 @@
GList * gimp_dynamics_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);

View File

@ -41,39 +41,44 @@
GList *
gimp_gradient_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
GimpGradient *gradient;
GimpGradientSegment *prev;
gint num_segments;
gint i;
FILE *file;
gchar *path;
FILE *f;
gchar line[1024];
gint linenum;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
path = g_file_get_path (file);
g_return_val_if_fail (g_path_is_absolute (path), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
file = g_fopen (filename, "rb");
if (!file)
f = g_fopen (path, "rb");
if (! f)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_filename_to_utf8 (path), g_strerror (errno));
g_free (path);
return NULL;
}
linenum = 1;
if (! fgets (line, sizeof (line), file))
if (! fgets (line, sizeof (line), f))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': "
"Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum);
fclose (file);
gimp_filename_to_utf8 (path), linenum);
fclose (f);
g_free (path);
return NULL;
}
@ -82,8 +87,9 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': "
"Not a GIMP gradient file."),
gimp_filename_to_utf8 (filename));
fclose (file);
gimp_filename_to_utf8 (path));
fclose (f);
g_free (path);
return NULL;
}
@ -92,13 +98,14 @@ gimp_gradient_load (GimpContext *context,
NULL);
linenum++;
if (! fgets (line, sizeof (line), file))
if (! fgets (line, sizeof (line), f))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': "
"Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum);
fclose (file);
gimp_filename_to_utf8 (path), linenum);
fclose (f);
g_free (path);
g_object_unref (gradient);
return NULL;
}
@ -109,17 +116,18 @@ gimp_gradient_load (GimpContext *context,
utf8 = gimp_any_to_utf8 (g_strstrip (line + strlen ("Name: ")), -1,
_("Invalid UTF-8 string in gradient file '%s'."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
gimp_object_take_name (GIMP_OBJECT (gradient), utf8);
linenum++;
if (! fgets (line, sizeof (line), file))
if (! fgets (line, sizeof (line), f))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': "
"Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum);
fclose (file);
gimp_filename_to_utf8 (path), linenum);
fclose (f);
g_free (path);
g_object_unref (gradient);
return NULL;
}
@ -127,7 +135,7 @@ gimp_gradient_load (GimpContext *context,
else /* old gradient format */
{
gimp_object_take_name (GIMP_OBJECT (gradient),
g_filename_display_basename (filename));
g_filename_display_basename (path));
}
num_segments = atoi (line);
@ -137,9 +145,10 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': "
"File is corrupt in line %d."),
gimp_filename_to_utf8 (filename), linenum);
gimp_filename_to_utf8 (path), linenum);
g_object_unref (gradient);
fclose (file);
fclose (f);
g_free (path);
return NULL;
}
@ -164,13 +173,14 @@ gimp_gradient_load (GimpContext *context,
gradient->segments = seg;
linenum++;
if (! fgets (line, sizeof (line), file))
if (! fgets (line, sizeof (line), f))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': "
"Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum);
fclose (file);
gimp_filename_to_utf8 (path), linenum);
fclose (f);
g_free (path);
g_object_unref (gradient);
return NULL;
}
@ -219,9 +229,10 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': "
"Corrupt segment %d in line %d."),
gimp_filename_to_utf8 (filename), i, linenum);
gimp_filename_to_utf8 (path), i, linenum);
g_object_unref (gradient);
fclose (file);
fclose (f);
g_free (path);
return NULL;
}
}
@ -230,9 +241,10 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': "
"Corrupt segment %d in line %d."),
gimp_filename_to_utf8 (filename), i, linenum);
gimp_filename_to_utf8 (path), i, linenum);
g_object_unref (gradient);
fclose (file);
fclose (f);
g_free (path);
return NULL;
}
@ -242,9 +254,10 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Gradient file '%s' is corrupt: "
"Segments do not span the range 0-1."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
g_object_unref (gradient);
fclose (file);
fclose (f);
g_free (path);
return NULL;
}
@ -256,13 +269,15 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Gradient file '%s' is corrupt: "
"Segments do not span the range 0-1."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
g_object_unref (gradient);
fclose (file);
fclose (f);
g_free (path);
return NULL;
}
fclose (file);
fclose (f);
g_free (path);
return g_list_prepend (NULL, gradient);
}
@ -314,20 +329,24 @@ static const GMarkupParser markup_parser =
GList *
gimp_gradient_load_svg (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
GimpXmlParser *xml_parser;
SvgParser parser = { NULL, };
gchar *path;
gboolean success;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
path = g_file_get_path (file);
g_return_val_if_fail (g_path_is_absolute (path), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
xml_parser = gimp_xml_parser_new (&markup_parser, &parser);
success = gimp_xml_parser_parse_file (xml_parser, filename, error);
success = gimp_xml_parser_parse_gfile (xml_parser, file, error);
gimp_xml_parser_free (xml_parser);
@ -335,7 +354,7 @@ gimp_gradient_load_svg (GimpContext *context,
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("No linear gradients found in '%s'"),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
}
else
{
@ -345,7 +364,7 @@ gimp_gradient_load_svg (GimpContext *context,
(*error)->message =
g_strdup_printf (_("Failed to import gradients from '%s': %s"),
gimp_filename_to_utf8 (filename), msg);
gimp_filename_to_utf8 (path), msg);
g_free (msg);
}
@ -364,6 +383,8 @@ gimp_gradient_load_svg (GimpContext *context,
g_list_free (parser.stops);
}
g_free (path);
return g_list_reverse (parser.gradients);
}

View File

@ -24,10 +24,10 @@
GList * gimp_gradient_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);
GList * gimp_gradient_load_svg (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);

View File

@ -48,28 +48,32 @@
GList *
gimp_palette_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
FILE *file;
gchar *path;
FILE *f;
GList *glist;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
path = g_file_get_path (file);
g_return_val_if_fail (g_path_is_absolute (path), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
file = g_fopen (filename, "rb");
if (! file)
f = g_fopen (path, "rb");
if (! f)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_filename_to_utf8 (path), g_strerror (errno));
g_free (path);
return NULL;
}
glist = gimp_palette_load_gpl (context, filename, file, error);
fclose (file);
glist = gimp_palette_load_gpl (context, path, f, error);
fclose (f);
return glist;
}

View File

@ -35,7 +35,7 @@ typedef enum
GList * gimp_palette_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);
GList * gimp_palette_load_gpl (GimpContext *context,
const gchar *filename,
@ -63,7 +63,7 @@ GList * gimp_palette_load_css (GimpContext *context,
GError **error);
GimpPaletteFileFormat gimp_palette_load_detect_format (const gchar *filename,
FILE *file);
FILE *file);
#endif /* __GIMP_PALETTE_H__ */

View File

@ -60,26 +60,31 @@
GList *
gimp_pattern_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
GimpPattern *pattern = NULL;
const Babl *format = NULL;
gchar *path;
gint fd;
PatternHeader header;
gint bn_size;
gchar *name = NULL;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
path = g_file_get_path (file);
g_return_val_if_fail (g_path_is_absolute (path), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
fd = g_open (filename, O_RDONLY | _O_BINARY, 0);
fd = g_open (path, O_RDONLY | _O_BINARY, 0);
if (fd == -1)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_filename_to_utf8 (path), g_strerror (errno));
g_free (path);
return NULL;
}
@ -89,7 +94,7 @@ gimp_pattern_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': "
"File appears truncated."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
goto error;
}
@ -108,7 +113,7 @@ gimp_pattern_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': "
"Unknown pattern format version %d."),
gimp_filename_to_utf8 (filename), header.version);
gimp_filename_to_utf8 (path), header.version);
goto error;
}
@ -119,7 +124,7 @@ gimp_pattern_load (GimpContext *context,
_("Fatal parse error in pattern file '%s: "
"Unsupported pattern depth %d.\n"
"GIMP Patterns must be GRAY or RGB."),
gimp_filename_to_utf8 (filename), header.bytes);
gimp_filename_to_utf8 (path), header.bytes);
goto error;
}
@ -135,14 +140,14 @@ gimp_pattern_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': "
"File appears truncated."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
g_free (name);
goto error;
}
utf8 = gimp_any_to_utf8 (name, -1,
_("Invalid UTF-8 string in pattern file '%s'."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
g_free (name);
name = utf8;
}
@ -174,11 +179,12 @@ gimp_pattern_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': "
"File appears truncated."),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
goto error;
}
close (fd);
g_free (path);
return g_list_prepend (NULL, pattern);
@ -187,27 +193,35 @@ gimp_pattern_load (GimpContext *context,
g_object_unref (pattern);
close (fd);
g_free (path);
return NULL;
}
GList *
gimp_pattern_load_pixbuf (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
GimpPattern *pattern;
GdkPixbuf *pixbuf;
gchar *path;
gchar *name;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
path = g_file_get_path (file);
g_return_val_if_fail (g_path_is_absolute (path), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
pixbuf = gdk_pixbuf_new_from_file (filename, error);
pixbuf = gdk_pixbuf_new_from_file (path, error);
if (! pixbuf)
return NULL;
{
g_free (path);
return NULL;
}
name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Title"));
@ -215,7 +229,7 @@ gimp_pattern_load_pixbuf (GimpContext *context,
name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Comment"));
if (! name)
name = g_filename_display_basename (filename);
name = g_filename_display_basename (path);
pattern = g_object_new (GIMP_TYPE_PATTERN,
"name", name,
@ -226,6 +240,7 @@ gimp_pattern_load_pixbuf (GimpContext *context,
pattern->mask = gimp_temp_buf_new_from_pixbuf (pixbuf, NULL);
g_object_unref (pixbuf);
g_free (path);
return g_list_prepend (NULL, pattern);
}

View File

@ -23,10 +23,10 @@
GList * gimp_pattern_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);
GList * gimp_pattern_load_pixbuf (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);

View File

@ -34,23 +34,22 @@
GList *
gimp_tool_preset_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error)
{
GimpToolPreset *tool_preset;
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
tool_preset = g_object_new (GIMP_TYPE_TOOL_PRESET,
"gimp", context->gimp,
NULL);
if (gimp_config_deserialize_file (GIMP_CONFIG (tool_preset),
filename,
NULL, error))
if (gimp_config_deserialize_gfile (GIMP_CONFIG (tool_preset),
file,
NULL, error))
{
if (GIMP_IS_CONTEXT (tool_preset->tool_options))
{
@ -58,9 +57,12 @@ gimp_tool_preset_load (GimpContext *context,
}
else
{
gchar *path = g_file_get_path (file);
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
_("Error while parsing '%s'"),
gimp_filename_to_utf8 (filename));
gimp_filename_to_utf8 (path));
g_free (path);
}
}

View File

@ -23,7 +23,7 @@
GList * gimp_tool_preset_load (GimpContext *context,
const gchar *filename,
GFile *file,
GError **error);