app: use gimp_file_get_utf8_name() in the code ported to GFile earlier

This commit is contained in:
Michael Natterer 2014-07-01 14:25:37 +02:00
parent 776a79792d
commit 20032907e0
14 changed files with 264 additions and 309 deletions

View File

@ -87,36 +87,36 @@ struct _AbrSampledBrushHeader
/* local function prototypes */ /* local function prototypes */
static GList * gimp_brush_load_abr_v12 (FILE *file, static GList * gimp_brush_load_abr_v12 (FILE *f,
AbrHeader *abr_hdr, AbrHeader *abr_hdr,
const gchar *path, GFile *file,
GError **error); GError **error);
static GList * gimp_brush_load_abr_v6 (FILE *file, static GList * gimp_brush_load_abr_v6 (FILE *f,
AbrHeader *abr_hdr, AbrHeader *abr_hdr,
const gchar *path, GFile *file,
GError **error); GError **error);
static GimpBrush * gimp_brush_load_abr_brush_v12 (FILE *file, static GimpBrush * gimp_brush_load_abr_brush_v12 (FILE *f,
AbrHeader *abr_hdr, AbrHeader *abr_hdr,
gint index, gint index,
const gchar *path, GFile *file,
GError **error); GError **error);
static GimpBrush * gimp_brush_load_abr_brush_v6 (FILE *file, static GimpBrush * gimp_brush_load_abr_brush_v6 (FILE *f,
AbrHeader *abr_hdr, AbrHeader *abr_hdr,
gint32 max_offset, gint32 max_offset,
gint index, gint index,
const gchar *path, GFile *file,
GError **error); GError **error);
static gchar abr_read_char (FILE *file); static gchar abr_read_char (FILE *f);
static gint16 abr_read_short (FILE *file); static gint16 abr_read_short (FILE *f);
static gint32 abr_read_long (FILE *file); static gint32 abr_read_long (FILE *f);
static gchar * abr_read_ucs2_text (FILE *file); static gchar * abr_read_ucs2_text (FILE *f);
static gboolean abr_supported (AbrHeader *abr_hdr, static gboolean abr_supported (AbrHeader *abr_hdr,
const gchar *path, GFile *f,
GError **error); GError **error);
static gboolean abr_reach_8bim_section (FILE *abr, static gboolean abr_reach_8bim_section (FILE *abr,
const gchar *name); const gchar *name);
static gint32 abr_rle_decode (FILE *file, static gint32 abr_rle_decode (FILE *f,
gchar *buffer, gchar *buffer,
gint32 height); gint32 height);
@ -140,19 +140,19 @@ gimp_brush_load (GimpContext *context,
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
fd = g_open (path, O_RDONLY | _O_BINARY, 0); fd = g_open (path, O_RDONLY | _O_BINARY, 0);
g_free (path);
if (fd == -1) if (fd == -1)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"), _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (path), g_strerror (errno)); gimp_file_get_utf8_name (file), g_strerror (errno));
g_free (path);
return NULL; return NULL;
} }
brush = gimp_brush_load_brush (context, fd, path, error); brush = gimp_brush_load_brush (context, file, fd, error);
close (fd); close (fd);
g_free (path);
if (! brush) if (! brush)
return NULL; return NULL;
@ -162,8 +162,8 @@ gimp_brush_load (GimpContext *context,
GimpBrush * GimpBrush *
gimp_brush_load_brush (GimpContext *context, gimp_brush_load_brush (GimpContext *context,
GFile *file,
gint fd, gint fd,
const gchar *path,
GError **error) GError **error)
{ {
GimpBrush *brush; GimpBrush *brush;
@ -175,7 +175,7 @@ gimp_brush_load_brush (GimpContext *context,
gssize i, size; gssize i, size;
gboolean success = TRUE; gboolean success = TRUE;
g_return_val_if_fail (path != NULL, NULL); g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (fd != -1, NULL); g_return_val_if_fail (fd != -1, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@ -187,7 +187,7 @@ gimp_brush_load_brush (GimpContext *context,
"Could not read %d bytes from '%s': %s", "Could not read %d bytes from '%s': %s",
(gint) sizeof (header)), (gint) sizeof (header)),
(gint) sizeof (header), (gint) sizeof (header),
gimp_filename_to_utf8 (path), g_strerror (errno)); gimp_file_get_utf8_name (file), g_strerror (errno));
return NULL; return NULL;
} }
@ -207,7 +207,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"Width = 0."), "Width = 0."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
return NULL; return NULL;
} }
@ -216,7 +216,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"Height = 0."), "Height = 0."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
return NULL; return NULL;
} }
@ -225,7 +225,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"Bytes = 0."), "Bytes = 0."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
return NULL; return NULL;
} }
@ -249,7 +249,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"Unknown depth %d."), "Unknown depth %d."),
gimp_filename_to_utf8 (path), header.bytes); gimp_file_get_utf8_name (file), header.bytes);
return NULL; return NULL;
} }
/* fallthrough */ /* fallthrough */
@ -262,7 +262,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"Unknown version %d."), "Unknown version %d."),
gimp_filename_to_utf8 (path), header.version); gimp_file_get_utf8_name (file), header.version);
return NULL; return NULL;
} }
@ -278,14 +278,14 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"File appears truncated."), "File appears truncated."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
g_free (name); g_free (name);
return NULL; return NULL;
} }
utf8 = gimp_any_to_utf8 (name, -1, utf8 = gimp_any_to_utf8 (name, -1,
_("Invalid UTF-8 string in brush file '%s'."), _("Invalid UTF-8 string in brush file '%s'."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
g_free (name); g_free (name);
name = utf8; name = utf8;
} }
@ -363,7 +363,7 @@ gimp_brush_load_brush (GimpContext *context,
"GIMP brushes must be GRAY or RGBA.\n" "GIMP brushes must be GRAY or RGBA.\n"
"This might be an obsolete GIMP brush file, try " "This might be an obsolete GIMP brush file, try "
"loading it as image and save it again."), "loading it as image and save it again."),
gimp_filename_to_utf8 (path), header.bytes); gimp_file_get_utf8_name (file), header.bytes);
return NULL; return NULL;
break; break;
@ -406,7 +406,7 @@ gimp_brush_load_brush (GimpContext *context,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"Unsupported brush depth %d\n" "Unsupported brush depth %d\n"
"GIMP brushes must be GRAY or RGBA."), "GIMP brushes must be GRAY or RGBA."),
gimp_filename_to_utf8 (path), header.bytes); gimp_file_get_utf8_name (file), header.bytes);
return NULL; return NULL;
} }
@ -416,7 +416,7 @@ gimp_brush_load_brush (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"File appears truncated."), "File appears truncated."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
return NULL; return NULL;
} }
@ -447,31 +447,32 @@ gimp_brush_load_abr (GimpContext *context,
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
f = g_fopen (path, "rb"); f = g_fopen (path, "rb");
g_free (path);
if (! f) if (! f)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"), _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (path), g_strerror (errno)); gimp_file_get_utf8_name (file), g_strerror (errno));
g_free (path);
return NULL; return NULL;
} }
abr_hdr.version = abr_read_short (f); abr_hdr.version = abr_read_short (f);
abr_hdr.count = abr_read_short (f); /* sub-version for ABR v6 */ abr_hdr.count = abr_read_short (f); /* sub-version for ABR v6 */
if (abr_supported (&abr_hdr, path, error)) if (abr_supported (&abr_hdr, file, error))
{ {
switch (abr_hdr.version) switch (abr_hdr.version)
{ {
case 1: case 1:
case 2: case 2:
brush_list = gimp_brush_load_abr_v12 (f, &abr_hdr, brush_list = gimp_brush_load_abr_v12 (f, &abr_hdr,
path, error); file, error);
break; break;
case 6: case 6:
brush_list = gimp_brush_load_abr_v6 (f, &abr_hdr, brush_list = gimp_brush_load_abr_v6 (f, &abr_hdr,
path, error); file, error);
} }
} }
@ -481,9 +482,7 @@ gimp_brush_load_abr (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"unable to decode abr format version %d."), "unable to decode abr format version %d."),
gimp_filename_to_utf8 (path), abr_hdr.version); gimp_file_get_utf8_name (file), abr_hdr.version);
g_free (path);
return g_list_reverse (brush_list); return g_list_reverse (brush_list);
} }
@ -492,10 +491,10 @@ gimp_brush_load_abr (GimpContext *context,
/* private functions */ /* private functions */
static GList * static GList *
gimp_brush_load_abr_v12 (FILE *file, gimp_brush_load_abr_v12 (FILE *f,
AbrHeader *abr_hdr, AbrHeader *abr_hdr,
const gchar *path, GFile *file,
GError **error) GError **error)
{ {
GList *brush_list = NULL; GList *brush_list = NULL;
gint i; gint i;
@ -505,8 +504,8 @@ gimp_brush_load_abr_v12 (FILE *file,
GimpBrush *brush; GimpBrush *brush;
GError *my_error = NULL; GError *my_error = NULL;
brush = gimp_brush_load_abr_brush_v12 (file, abr_hdr, i, brush = gimp_brush_load_abr_brush_v12 (f, abr_hdr, i,
path, &my_error); file, &my_error);
/* a NULL brush without an error means an unsupported brush /* a NULL brush without an error means an unsupported brush
* type was encountered, silently skip it and try the next one * type was encountered, silently skip it and try the next one
@ -527,29 +526,29 @@ gimp_brush_load_abr_v12 (FILE *file,
} }
static GList * static GList *
gimp_brush_load_abr_v6 (FILE *file, gimp_brush_load_abr_v6 (FILE *f,
AbrHeader *abr_hdr, AbrHeader *abr_hdr,
const gchar *path, GFile *file,
GError **error) GError **error)
{ {
GList *brush_list = NULL; GList *brush_list = NULL;
gint32 sample_section_size; gint32 sample_section_size;
gint32 sample_section_end; gint32 sample_section_end;
gint i = 1; gint i = 1;
if (! abr_reach_8bim_section (file, "samp")) if (! abr_reach_8bim_section (f, "samp"))
return brush_list; return brush_list;
sample_section_size = abr_read_long (file); sample_section_size = abr_read_long (f);
sample_section_end = sample_section_size + ftell (file); sample_section_end = sample_section_size + ftell (f);
while (ftell (file) < sample_section_end) while (ftell (f) < sample_section_end)
{ {
GimpBrush *brush; GimpBrush *brush;
GError *my_error = NULL; GError *my_error = NULL;
brush = gimp_brush_load_abr_brush_v6 (file, abr_hdr, sample_section_end, brush = gimp_brush_load_abr_brush_v6 (f, abr_hdr, sample_section_end,
i, path, &my_error); i, file, &my_error);
/* a NULL brush without an error means an unsupported brush /* a NULL brush without an error means an unsupported brush
* type was encountered, silently skip it and try the next one * type was encountered, silently skip it and try the next one
@ -572,20 +571,17 @@ gimp_brush_load_abr_v6 (FILE *file,
} }
static GimpBrush * static GimpBrush *
gimp_brush_load_abr_brush_v12 (FILE *file, gimp_brush_load_abr_brush_v12 (FILE *f,
AbrHeader *abr_hdr, AbrHeader *abr_hdr,
gint index, gint index,
const gchar *path, GFile *file,
GError **error) GError **error)
{ {
GimpBrush *brush = NULL; GimpBrush *brush = NULL;
AbrBrushHeader abr_brush_hdr; AbrBrushHeader abr_brush_hdr;
g_return_val_if_fail (path != NULL, NULL); abr_brush_hdr.type = abr_read_short (f);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); abr_brush_hdr.size = abr_read_long (f);
abr_brush_hdr.type = abr_read_short (file);
abr_brush_hdr.size = abr_read_long (file);
/* g_print(" + BRUSH\n | << type: %i block size: %i bytes\n", /* g_print(" + BRUSH\n | << type: %i block size: %i bytes\n",
* abr_brush_hdr.type, abr_brush_hdr.size); * abr_brush_hdr.type, abr_brush_hdr.size);
@ -601,7 +597,7 @@ gimp_brush_load_abr_brush_v12 (FILE *file,
* types -akl * types -akl
*/ */
g_printerr ("WARNING: computed brush unsupported, skipping.\n"); g_printerr ("WARNING: computed brush unsupported, skipping.\n");
fseek (file, abr_brush_hdr.size, SEEK_CUR); fseek (f, abr_brush_hdr.size, SEEK_CUR);
break; break;
case 2: /* sampled brush */ case 2: /* sampled brush */
@ -617,21 +613,21 @@ gimp_brush_load_abr_brush_v12 (FILE *file,
gchar *tmp; gchar *tmp;
gshort compress; gshort compress;
abr_sampled_brush_hdr.misc = abr_read_long (file); abr_sampled_brush_hdr.misc = abr_read_long (f);
abr_sampled_brush_hdr.spacing = abr_read_short (file); abr_sampled_brush_hdr.spacing = abr_read_short (f);
if (abr_hdr->version == 2) if (abr_hdr->version == 2)
sample_name = abr_read_ucs2_text (file); sample_name = abr_read_ucs2_text (f);
abr_sampled_brush_hdr.antialiasing = abr_read_char (file); abr_sampled_brush_hdr.antialiasing = abr_read_char (f);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
abr_sampled_brush_hdr.bounds[i] = abr_read_short (file); abr_sampled_brush_hdr.bounds[i] = abr_read_short (f);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
abr_sampled_brush_hdr.bounds_long[i] = abr_read_long (file); abr_sampled_brush_hdr.bounds_long[i] = abr_read_long (f);
abr_sampled_brush_hdr.depth = abr_read_short (file); abr_sampled_brush_hdr.depth = abr_read_short (f);
height = (abr_sampled_brush_hdr.bounds_long[2] - height = (abr_sampled_brush_hdr.bounds_long[2] -
abr_sampled_brush_hdr.bounds_long[0]); /* bottom - top */ abr_sampled_brush_hdr.bounds_long[0]); /* bottom - top */
@ -650,11 +646,11 @@ gimp_brush_load_abr_brush_v12 (FILE *file,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"Wide brushes are not supported."), "Wide brushes are not supported."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
return NULL; return NULL;
} }
tmp = g_filename_display_basename (path); tmp = g_path_get_basename (gimp_file_get_utf8_name (file));
if (! sample_name) if (! sample_name)
{ {
/* build name from filename and index */ /* build name from filename and index */
@ -687,7 +683,7 @@ gimp_brush_load_abr_brush_v12 (FILE *file,
mask = gimp_temp_buf_get_data (brush->mask); mask = gimp_temp_buf_get_data (brush->mask);
size = width * height * bytes; size = width * height * bytes;
compress = abr_read_char (file); compress = abr_read_char (f);
/* g_print(" | << size: %dx%d %d bit (%d bytes) %s\n", /* g_print(" | << size: %dx%d %d bit (%d bytes) %s\n",
* width, height, abr_sampled_brush_hdr.depth, size, * width, height, abr_sampled_brush_hdr.depth, size,
@ -695,15 +691,15 @@ gimp_brush_load_abr_brush_v12 (FILE *file,
*/ */
if (! compress) if (! compress)
fread (mask, size, 1, file); fread (mask, size, 1, f);
else else
abr_rle_decode (file, (gchar *) mask, height); abr_rle_decode (f, (gchar *) mask, height);
} }
break; break;
default: default:
g_printerr ("WARNING: unknown brush type, skipping.\n"); g_printerr ("WARNING: unknown brush type, skipping.\n");
fseek (file, abr_brush_hdr.size, SEEK_CUR); fseek (f, abr_brush_hdr.size, SEEK_CUR);
break; break;
} }
@ -711,12 +707,12 @@ gimp_brush_load_abr_brush_v12 (FILE *file,
} }
static GimpBrush * static GimpBrush *
gimp_brush_load_abr_brush_v6 (FILE *file, gimp_brush_load_abr_brush_v6 (FILE *f,
AbrHeader *abr_hdr, AbrHeader *abr_hdr,
gint32 max_offset, gint32 max_offset,
gint index, gint index,
const gchar *path, GFile *file,
GError **error) GError **error)
{ {
GimpBrush *brush = NULL; GimpBrush *brush = NULL;
guchar *mask; guchar *mask;
@ -736,43 +732,43 @@ gimp_brush_load_abr_brush_v6 (FILE *file,
gchar *name; gchar *name;
gint r; gint r;
brush_size = abr_read_long (file); brush_size = abr_read_long (f);
brush_end = brush_size; brush_end = brush_size;
/* complement to 4 */ /* complement to 4 */
while (brush_end % 4 != 0) while (brush_end % 4 != 0)
brush_end++; brush_end++;
next_brush = ftell (file) + brush_end; next_brush = ftell (f) + brush_end;
if (abr_hdr->count == 1) if (abr_hdr->count == 1)
/* discard key and short coordinates and unknown short */ /* discard key and short coordinates and unknown short */
r = fseek (file, 47, SEEK_CUR); r = fseek (f, 47, SEEK_CUR);
else else
/* discard key and unknown bytes */ /* discard key and unknown bytes */
r = fseek (file, 301, SEEK_CUR); r = fseek (f, 301, SEEK_CUR);
if (r == -1) if (r == -1)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"File appears truncated."), "File appears truncated."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
return NULL; return NULL;
} }
top = abr_read_long (file); top = abr_read_long (f);
left = abr_read_long (file); left = abr_read_long (f);
bottom = abr_read_long (file); bottom = abr_read_long (f);
right = abr_read_long (file); right = abr_read_long (f);
depth = abr_read_short (file); depth = abr_read_short (f);
compress = abr_read_char (file); compress = abr_read_char (f);
width = right - left; width = right - left;
height = bottom - top; height = bottom - top;
size = width * (depth >> 3) * height; size = width * (depth >> 3) * height;
tmp = g_filename_display_basename (path); tmp = g_path_get_basename (gimp_file_get_utf8_name (file));
name = g_strdup_printf ("%s-%03d", tmp, index); name = g_strdup_printf ("%s-%03d", tmp, index);
g_free (tmp); g_free (tmp);
@ -797,43 +793,43 @@ gimp_brush_load_abr_brush_v6 (FILE *file,
/* data decoding */ /* data decoding */
if (! compress) if (! compress)
/* not compressed - read raw bytes as brush data */ /* not compressed - read raw bytes as brush data */
fread (mask, size, 1, file); fread (mask, size, 1, f);
else else
abr_rle_decode (file, (gchar *) mask, height); abr_rle_decode (f, (gchar *) mask, height);
fseek (file, next_brush, SEEK_SET); fseek (f, next_brush, SEEK_SET);
return brush; return brush;
} }
static gchar static gchar
abr_read_char (FILE *file) abr_read_char (FILE *f)
{ {
return fgetc (file); return fgetc (f);
} }
static gint16 static gint16
abr_read_short (FILE *file) abr_read_short (FILE *f)
{ {
gint16 val; gint16 val;
fread (&val, sizeof (val), 1, file); fread (&val, sizeof (val), 1, f);
return GINT16_FROM_BE (val); return GINT16_FROM_BE (val);
} }
static gint32 static gint32
abr_read_long (FILE *file) abr_read_long (FILE *f)
{ {
gint32 val; gint32 val;
fread (&val, sizeof (val), 1, file); fread (&val, sizeof (val), 1, f);
return GINT32_FROM_BE (val); return GINT32_FROM_BE (val);
} }
static gchar * static gchar *
abr_read_ucs2_text (FILE *file) abr_read_ucs2_text (FILE *f)
{ {
gchar *name_ucs2; gchar *name_ucs2;
gchar *name_utf8; gchar *name_utf8;
@ -846,14 +842,14 @@ abr_read_ucs2_text (FILE *file)
* data : zero terminated UCS-2 string * data : zero terminated UCS-2 string
*/ */
len = 2 * abr_read_long (file); len = 2 * abr_read_long (f);
if (len <= 0) if (len <= 0)
return NULL; return NULL;
name_ucs2 = g_new (gchar, len); name_ucs2 = g_new (gchar, len);
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
name_ucs2[i] = abr_read_char (file); name_ucs2[i] = abr_read_char (f);
name_utf8 = g_convert (name_ucs2, len, name_utf8 = g_convert (name_ucs2, len,
"UTF-8", "UCS-2BE", "UTF-8", "UCS-2BE",
@ -865,9 +861,9 @@ abr_read_ucs2_text (FILE *file)
} }
static gboolean static gboolean
abr_supported (AbrHeader *abr_hdr, abr_supported (AbrHeader *abr_hdr,
const gchar *path, GFile *file,
GError **error) GError **error)
{ {
switch (abr_hdr->version) switch (abr_hdr->version)
{ {
@ -885,7 +881,7 @@ abr_supported (AbrHeader *abr_hdr,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"unable to decode abr format version %d."), "unable to decode abr format version %d."),
gimp_filename_to_utf8 (path), gimp_file_get_utf8_name (file),
/* horrid subversion display, but better than /* horrid subversion display, but better than
* having yet another translatable string for * having yet another translatable string for
@ -935,7 +931,7 @@ abr_reach_8bim_section (FILE *abr,
} }
static gint32 static gint32
abr_rle_decode (FILE *file, abr_rle_decode (FILE *f,
gchar *buffer, gchar *buffer,
gint32 height) gint32 height)
{ {
@ -947,14 +943,14 @@ abr_rle_decode (FILE *file,
/* read compressed size foreach scanline */ /* read compressed size foreach scanline */
cscanline_len = g_new0 (gshort, height); cscanline_len = g_new0 (gshort, height);
for (i = 0; i < height; i++) for (i = 0; i < height; i++)
cscanline_len[i] = abr_read_short (file); cscanline_len[i] = abr_read_short (f);
/* unpack each scanline data */ /* unpack each scanline data */
for (i = 0; i < height; i++) for (i = 0; i < height; i++)
{ {
for (j = 0; j < cscanline_len[i];) for (j = 0; j < cscanline_len[i];)
{ {
gint32 n = abr_read_char (file); gint32 n = abr_read_char (f);
j++; j++;
@ -969,7 +965,7 @@ abr_rle_decode (FILE *file,
continue; continue;
n = -n + 1; n = -n + 1;
ch = abr_read_char (file); ch = abr_read_char (f);
j++; j++;
for (c = 0; c < n; c++, data++) for (c = 0; c < n; c++, data++)
@ -980,7 +976,7 @@ abr_rle_decode (FILE *file,
/* read the following n + 1 chars (no compr) */ /* read the following n + 1 chars (no compr) */
for (c = 0; c < n + 1; c++, j++, data++) for (c = 0; c < n + 1; c++, j++, data++)
*data = abr_read_char (file); *data = abr_read_char (f);
} }
} }
} }

View File

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

View File

@ -69,12 +69,13 @@ gimp_brush_generated_load (GimpContext *context,
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
f = g_fopen (path, "rb"); f = g_fopen (path, "rb");
g_free (path);
if (! f) if (! f)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"), _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (path), g_strerror (errno)); gimp_file_get_utf8_name (file), g_strerror (errno));
g_free (path);
return NULL; return NULL;
} }
@ -89,7 +90,7 @@ gimp_brush_generated_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"Not a GIMP brush file."), "Not a GIMP brush file."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
goto failed; goto failed;
} }
@ -106,7 +107,7 @@ gimp_brush_generated_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"Unknown GIMP brush version in line %d."), "Unknown GIMP brush version in line %d."),
gimp_filename_to_utf8 (path), linenum); gimp_file_get_utf8_name (file), linenum);
goto failed; goto failed;
} }
else else
@ -129,7 +130,7 @@ gimp_brush_generated_load (GimpContext *context,
name = gimp_any_to_utf8 (string, -1, name = gimp_any_to_utf8 (string, -1,
_("Invalid UTF-8 string in brush file '%s'."), _("Invalid UTF-8 string in brush file '%s'."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
if (have_shape) if (have_shape)
{ {
@ -152,7 +153,7 @@ gimp_brush_generated_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"Unknown GIMP brush shape in line %d."), "Unknown GIMP brush shape in line %d."),
gimp_filename_to_utf8 (path), linenum); gimp_file_get_utf8_name (file), linenum);
goto failed; goto failed;
} }
@ -212,8 +213,6 @@ gimp_brush_generated_load (GimpContext *context,
brush->spacing = spacing; brush->spacing = spacing;
g_free (path);
return g_list_prepend (NULL, brush); return g_list_prepend (NULL, brush);
failed: failed:
@ -234,12 +233,10 @@ gimp_brush_generated_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Error while reading brush file '%s': %s"), _("Error while reading brush file '%s': %s"),
gimp_filename_to_utf8 (path), msg); gimp_file_get_utf8_name (file), msg);
g_free (msg); g_free (msg);
} }
g_free (path);
return NULL; return NULL;
} }

View File

@ -56,19 +56,17 @@ gimp_brush_generated_save (GimpData *data,
path = g_file_get_path (gimp_data_get_file (data)); path = g_file_get_path (gimp_data_get_file (data));
file = g_fopen (path, "wb"); file = g_fopen (path, "wb");
g_free (path);
if (! file) if (! file)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"), _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (path), gimp_file_get_utf8_name (gimp_data_get_file (data)),
g_strerror (errno)); g_strerror (errno));
g_free (path);
return FALSE; return FALSE;
} }
g_free (path);
/* write magic header */ /* write magic header */
fprintf (file, "GIMP-VBR\n"); fprintf (file, "GIMP-VBR\n");

View File

@ -77,12 +77,13 @@ gimp_brush_pipe_load (GimpContext *context,
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
fd = g_open (path, O_RDONLY | _O_BINARY, 0); fd = g_open (path, O_RDONLY | _O_BINARY, 0);
g_free (path);
if (fd == -1) if (fd == -1)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"), _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (path), g_strerror (errno)); gimp_file_get_utf8_name (file), g_strerror (errno));
g_free (path);
return NULL; return NULL;
} }
@ -98,7 +99,7 @@ gimp_brush_pipe_load (GimpContext *context,
gchar *utf8 = gchar *utf8 =
gimp_any_to_utf8 (buffer->str, buffer->len, gimp_any_to_utf8 (buffer->str, buffer->len,
_("Invalid UTF-8 string in brush file '%s'."), _("Invalid UTF-8 string in brush file '%s'."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
pipe = g_object_new (GIMP_TYPE_BRUSH_PIPE, pipe = g_object_new (GIMP_TYPE_BRUSH_PIPE,
"name", utf8, "name", utf8,
@ -115,9 +116,8 @@ gimp_brush_pipe_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"File is corrupt."), "File is corrupt."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
close (fd); close (fd);
g_free (path);
return NULL; return NULL;
} }
@ -136,9 +136,8 @@ gimp_brush_pipe_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': " _("Fatal parse error in brush file '%s': "
"File is corrupt."), "File is corrupt."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
close (fd); close (fd);
g_free (path);
g_object_unref (pipe); g_object_unref (pipe);
g_string_free (buffer, TRUE); g_string_free (buffer, TRUE);
return NULL; return NULL;
@ -218,7 +217,7 @@ gimp_brush_pipe_load (GimpContext *context,
GError *my_error = NULL; GError *my_error = NULL;
pipe->brushes[pipe->n_brushes] = gimp_brush_load_brush (context, pipe->brushes[pipe->n_brushes] = gimp_brush_load_brush (context,
fd, path, file, fd,
&my_error); &my_error);
if (pipe->brushes[pipe->n_brushes]) if (pipe->brushes[pipe->n_brushes])
@ -230,7 +229,6 @@ gimp_brush_pipe_load (GimpContext *context,
{ {
g_propagate_error (error, my_error); g_propagate_error (error, my_error);
close (fd); close (fd);
g_free (path);
g_object_unref (pipe); g_object_unref (pipe);
return NULL; return NULL;
} }
@ -250,7 +248,5 @@ gimp_brush_pipe_load (GimpContext *context,
GIMP_BRUSH (pipe)->mask = pipe->current->mask; GIMP_BRUSH (pipe)->mask = pipe->current->mask;
GIMP_BRUSH (pipe)->pixmap = pipe->current->pixmap; GIMP_BRUSH (pipe)->pixmap = pipe->current->pixmap;
g_free (path);
return g_list_prepend (NULL, pipe); return g_list_prepend (NULL, pipe);
} }

View File

@ -48,19 +48,17 @@ gimp_curve_save (GimpData *data,
path = g_file_get_path (gimp_data_get_file (data)); path = g_file_get_path (gimp_data_get_file (data));
file = g_fopen (path, "wb"); file = g_fopen (path, "wb");
g_free (path);
if (! file) if (! file)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"), _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (path), gimp_file_get_utf8_name (gimp_data_get_file (data)),
g_strerror (errno)); g_strerror (errno));
g_free (path);
return FALSE; return FALSE;
} }
g_free (path);
/* FIXME: write curve */ /* FIXME: write curve */
fclose (file); fclose (file);

View File

@ -61,12 +61,13 @@ gimp_gradient_load (GimpContext *context,
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
f = g_fopen (path, "rb"); f = g_fopen (path, "rb");
g_free (path);
if (! f) if (! f)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"), _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (path), g_strerror (errno)); gimp_file_get_utf8_name (file), g_strerror (errno));
g_free (path);
return NULL; return NULL;
} }
@ -76,9 +77,8 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': " _("Fatal parse error in gradient file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (path), linenum); gimp_file_get_utf8_name (file), linenum);
fclose (f); fclose (f);
g_free (path);
return NULL; return NULL;
} }
@ -87,9 +87,8 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': " _("Fatal parse error in gradient file '%s': "
"Not a GIMP gradient file."), "Not a GIMP gradient file."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
fclose (f); fclose (f);
g_free (path);
return NULL; return NULL;
} }
@ -103,9 +102,8 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': " _("Fatal parse error in gradient file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (path), linenum); gimp_file_get_utf8_name (file), linenum);
fclose (f); fclose (f);
g_free (path);
g_object_unref (gradient); g_object_unref (gradient);
return NULL; return NULL;
} }
@ -116,7 +114,7 @@ gimp_gradient_load (GimpContext *context,
utf8 = gimp_any_to_utf8 (g_strstrip (line + strlen ("Name: ")), -1, utf8 = gimp_any_to_utf8 (g_strstrip (line + strlen ("Name: ")), -1,
_("Invalid UTF-8 string in gradient file '%s'."), _("Invalid UTF-8 string in gradient file '%s'."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
gimp_object_take_name (GIMP_OBJECT (gradient), utf8); gimp_object_take_name (GIMP_OBJECT (gradient), utf8);
linenum++; linenum++;
@ -125,9 +123,8 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': " _("Fatal parse error in gradient file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (path), linenum); gimp_file_get_utf8_name (file), linenum);
fclose (f); fclose (f);
g_free (path);
g_object_unref (gradient); g_object_unref (gradient);
return NULL; return NULL;
} }
@ -135,7 +132,7 @@ gimp_gradient_load (GimpContext *context,
else /* old gradient format */ else /* old gradient format */
{ {
gimp_object_take_name (GIMP_OBJECT (gradient), gimp_object_take_name (GIMP_OBJECT (gradient),
g_filename_display_basename (path)); g_path_get_basename (gimp_file_get_utf8_name (file)));
} }
num_segments = atoi (line); num_segments = atoi (line);
@ -145,10 +142,9 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': " _("Fatal parse error in gradient file '%s': "
"File is corrupt in line %d."), "File is corrupt in line %d."),
gimp_filename_to_utf8 (path), linenum); gimp_file_get_utf8_name (file), linenum);
g_object_unref (gradient); g_object_unref (gradient);
fclose (f); fclose (f);
g_free (path);
return NULL; return NULL;
} }
@ -178,9 +174,8 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': " _("Fatal parse error in gradient file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (path), linenum); gimp_file_get_utf8_name (file), linenum);
fclose (f); fclose (f);
g_free (path);
g_object_unref (gradient); g_object_unref (gradient);
return NULL; return NULL;
} }
@ -229,10 +224,9 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': " _("Fatal parse error in gradient file '%s': "
"Corrupt segment %d in line %d."), "Corrupt segment %d in line %d."),
gimp_filename_to_utf8 (path), i, linenum); gimp_file_get_utf8_name (file), i, linenum);
g_object_unref (gradient); g_object_unref (gradient);
fclose (f); fclose (f);
g_free (path);
return NULL; return NULL;
} }
} }
@ -241,10 +235,9 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in gradient file '%s': " _("Fatal parse error in gradient file '%s': "
"Corrupt segment %d in line %d."), "Corrupt segment %d in line %d."),
gimp_filename_to_utf8 (path), i, linenum); gimp_file_get_utf8_name (file), i, linenum);
g_object_unref (gradient); g_object_unref (gradient);
fclose (f); fclose (f);
g_free (path);
return NULL; return NULL;
} }
@ -254,10 +247,9 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Gradient file '%s' is corrupt: " _("Gradient file '%s' is corrupt: "
"Segments do not span the range 0-1."), "Segments do not span the range 0-1."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
g_object_unref (gradient); g_object_unref (gradient);
fclose (f); fclose (f);
g_free (path);
return NULL; return NULL;
} }
@ -269,15 +261,13 @@ gimp_gradient_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Gradient file '%s' is corrupt: " _("Gradient file '%s' is corrupt: "
"Segments do not span the range 0-1."), "Segments do not span the range 0-1."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
g_object_unref (gradient); g_object_unref (gradient);
fclose (f); fclose (f);
g_free (path);
return NULL; return NULL;
} }
fclose (f); fclose (f);
g_free (path);
return g_list_prepend (NULL, gradient); return g_list_prepend (NULL, gradient);
} }
@ -334,14 +324,9 @@ gimp_gradient_load_svg (GimpContext *context,
{ {
GimpXmlParser *xml_parser; GimpXmlParser *xml_parser;
SvgParser parser = { NULL, }; SvgParser parser = { NULL, };
gchar *path;
gboolean success; gboolean success;
g_return_val_if_fail (G_IS_FILE (file), 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); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
xml_parser = gimp_xml_parser_new (&markup_parser, &parser); xml_parser = gimp_xml_parser_new (&markup_parser, &parser);
@ -354,7 +339,7 @@ gimp_gradient_load_svg (GimpContext *context,
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("No linear gradients found in '%s'"), _("No linear gradients found in '%s'"),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
} }
else else
{ {
@ -364,7 +349,7 @@ gimp_gradient_load_svg (GimpContext *context,
(*error)->message = (*error)->message =
g_strdup_printf (_("Failed to import gradients from '%s': %s"), g_strdup_printf (_("Failed to import gradients from '%s': %s"),
gimp_filename_to_utf8 (path), msg); gimp_file_get_utf8_name (file), msg);
g_free (msg); g_free (msg);
} }
@ -383,8 +368,6 @@ gimp_gradient_load_svg (GimpContext *context,
g_list_free (parser.stops); g_list_free (parser.stops);
} }
g_free (path);
return g_list_reverse (parser.gradients); return g_list_reverse (parser.gradients);
} }

View File

@ -46,19 +46,17 @@ gimp_gradient_save (GimpData *data,
path = g_file_get_path (gimp_data_get_file (data)); path = g_file_get_path (gimp_data_get_file (data));
file = g_fopen (path, "wb"); file = g_fopen (path, "wb");
g_free (path);
if (! file) if (! file)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"), _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (path), gimp_file_get_utf8_name (gimp_data_get_file (data)),
g_strerror (errno)); g_strerror (errno));
g_free (path);
return FALSE; return FALSE;
} }
g_free (path);
/* File format is: /* File format is:
* *
* GIMP Gradient * GIMP Gradient

View File

@ -499,17 +499,16 @@ gimp_palette_import_from_file (GimpContext *context,
GError **error) GError **error)
{ {
GList *palette_list = NULL; GList *palette_list = NULL;
GFile *file;
FILE *file; FILE *f;
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (palette_name != NULL, NULL); g_return_val_if_fail (palette_name != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
file = g_fopen (filename, "rb"); f = g_fopen (filename, "rb");
if (! f)
if (!file)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"), _("Could not open '%s' for reading: %s"),
@ -517,30 +516,32 @@ gimp_palette_import_from_file (GimpContext *context,
return NULL; return NULL;
} }
switch (gimp_palette_load_detect_format (filename, file)) file = g_file_new_for_path (filename);
switch (gimp_palette_load_detect_format (file, f))
{ {
case GIMP_PALETTE_FILE_FORMAT_GPL: case GIMP_PALETTE_FILE_FORMAT_GPL:
palette_list = gimp_palette_load_gpl (context, filename, file, error); palette_list = gimp_palette_load_gpl (context, file, f, error);
break; break;
case GIMP_PALETTE_FILE_FORMAT_ACT: case GIMP_PALETTE_FILE_FORMAT_ACT:
palette_list = gimp_palette_load_act (context, filename, file, error); palette_list = gimp_palette_load_act (context, file, f, error);
break; break;
case GIMP_PALETTE_FILE_FORMAT_RIFF_PAL: case GIMP_PALETTE_FILE_FORMAT_RIFF_PAL:
palette_list = gimp_palette_load_riff (context, filename, file, error); palette_list = gimp_palette_load_riff (context, file, f, error);
break; break;
case GIMP_PALETTE_FILE_FORMAT_PSP_PAL: case GIMP_PALETTE_FILE_FORMAT_PSP_PAL:
palette_list = gimp_palette_load_psp (context, filename, file, error); palette_list = gimp_palette_load_psp (context, file, f, error);
break; break;
case GIMP_PALETTE_FILE_FORMAT_ACO: case GIMP_PALETTE_FILE_FORMAT_ACO:
palette_list = gimp_palette_load_aco (context, filename, file, error); palette_list = gimp_palette_load_aco (context, file, f, error);
break; break;
case GIMP_PALETTE_FILE_FORMAT_CSS: case GIMP_PALETTE_FILE_FORMAT_CSS:
palette_list = gimp_palette_load_css (context, filename, file, error); palette_list = gimp_palette_load_css (context, file, f, error);
break; break;
default: default:
@ -551,7 +552,8 @@ gimp_palette_import_from_file (GimpContext *context,
break; break;
} }
fclose (file); g_object_unref (file);
fclose (f);
if (palette_list) if (palette_list)
{ {

View File

@ -46,6 +46,7 @@
#include "gimp-intl.h" #include "gimp-intl.h"
GList * GList *
gimp_palette_load (GimpContext *context, gimp_palette_load (GimpContext *context,
GFile *file, GFile *file,
@ -63,26 +64,26 @@ gimp_palette_load (GimpContext *context,
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
f = g_fopen (path, "rb"); f = g_fopen (path, "rb");
g_free (path);
if (! f) if (! f)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"), _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (path), g_strerror (errno)); gimp_file_get_utf8_name (file), g_strerror (errno));
g_free (path);
return NULL; return NULL;
} }
glist = gimp_palette_load_gpl (context, path, f, error); glist = gimp_palette_load_gpl (context, file, f, error);
fclose (f); fclose (f);
return glist; return glist;
} }
GList * GList *
gimp_palette_load_gpl (GimpContext *context, gimp_palette_load_gpl (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error) GError **error)
{ {
GimpPalette *palette; GimpPalette *palette;
@ -92,19 +93,18 @@ gimp_palette_load_gpl (GimpContext *context,
gint r, g, b; gint r, g, b;
gint linenum; gint linenum;
g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
r = g = b = 0; r = g = b = 0;
linenum = 1; linenum = 1;
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), f))
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_file_get_utf8_name (file), linenum);
return NULL; return NULL;
} }
@ -113,7 +113,7 @@ gimp_palette_load_gpl (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Missing magic header."), "Missing magic header."),
gimp_filename_to_utf8 (filename)); gimp_file_get_utf8_name (file));
return NULL; return NULL;
} }
@ -123,12 +123,12 @@ gimp_palette_load_gpl (GimpContext *context,
linenum++; linenum++;
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), f))
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_file_get_utf8_name (file), linenum);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
@ -139,16 +139,16 @@ gimp_palette_load_gpl (GimpContext *context,
utf8 = gimp_any_to_utf8 (g_strstrip (str + strlen ("Name: ")), -1, utf8 = gimp_any_to_utf8 (g_strstrip (str + strlen ("Name: ")), -1,
_("Invalid UTF-8 string in palette file '%s'"), _("Invalid UTF-8 string in palette file '%s'"),
gimp_filename_to_utf8 (filename)); gimp_file_get_utf8_name (file));
gimp_object_take_name (GIMP_OBJECT (palette), utf8); gimp_object_take_name (GIMP_OBJECT (palette), utf8);
linenum++; linenum++;
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), f))
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_file_get_utf8_name (file), linenum);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
@ -164,19 +164,19 @@ gimp_palette_load_gpl (GimpContext *context,
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Invalid number of columns in line %d. " "Invalid number of columns in line %d. "
"Using default value."), "Using default value."),
gimp_filename_to_utf8 (filename), linenum); gimp_file_get_utf8_name (file), linenum);
columns = 0; columns = 0;
} }
gimp_palette_set_columns (palette, columns); gimp_palette_set_columns (palette, columns);
linenum++; linenum++;
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), f))
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_file_get_utf8_name (file), linenum);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
@ -185,10 +185,10 @@ gimp_palette_load_gpl (GimpContext *context,
else /* old palette format */ else /* old palette format */
{ {
gimp_object_take_name (GIMP_OBJECT (palette), gimp_object_take_name (GIMP_OBJECT (palette),
g_filename_display_basename (filename)); g_path_get_basename (gimp_file_get_utf8_name (file)));
} }
while (! feof (file)) while (! feof (f))
{ {
if (str[0] != '#' && str[0] != '\n') if (str[0] != '#' && str[0] != '\n')
{ {
@ -198,7 +198,7 @@ gimp_palette_load_gpl (GimpContext *context,
else else
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Missing RED component in line %d."), "Missing RED component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_file_get_utf8_name (file), linenum);
tok = strtok (NULL, " \t"); tok = strtok (NULL, " \t");
if (tok) if (tok)
@ -206,7 +206,7 @@ gimp_palette_load_gpl (GimpContext *context,
else else
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Missing GREEN component in line %d."), "Missing GREEN component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_file_get_utf8_name (file), linenum);
tok = strtok (NULL, " \t"); tok = strtok (NULL, " \t");
if (tok) if (tok)
@ -214,7 +214,7 @@ gimp_palette_load_gpl (GimpContext *context,
else else
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Missing BLUE component in line %d."), "Missing BLUE component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_file_get_utf8_name (file), linenum);
/* optional name */ /* optional name */
tok = strtok (NULL, "\n"); tok = strtok (NULL, "\n");
@ -224,7 +224,7 @@ gimp_palette_load_gpl (GimpContext *context,
b < 0 || b > 255) b < 0 || b > 255)
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"RGB value out of range in line %d."), "RGB value out of range in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_file_get_utf8_name (file), linenum);
/* don't call gimp_palette_add_entry here, it's rather inefficient */ /* don't call gimp_palette_add_entry here, it's rather inefficient */
entry = g_slice_new0 (GimpPaletteEntry); entry = g_slice_new0 (GimpPaletteEntry);
@ -243,15 +243,15 @@ gimp_palette_load_gpl (GimpContext *context,
} }
linenum++; linenum++;
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), f))
{ {
if (feof (file)) if (feof (f))
break; break;
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_file_get_utf8_name (file), linenum);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
@ -264,20 +264,19 @@ gimp_palette_load_gpl (GimpContext *context,
GList * GList *
gimp_palette_load_act (GimpContext *context, gimp_palette_load_act (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error) GError **error)
{ {
GimpPalette *palette; GimpPalette *palette;
gchar *palette_name; gchar *palette_name;
gint fd = fileno (file); gint fd = fileno (f);
guchar color_bytes[4]; guchar color_bytes[4];
g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
palette_name = g_filename_display_basename (filename); palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
palette = GIMP_PALETTE (gimp_palette_new (context, palette_name)); palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
g_free (palette_name); g_free (palette_name);
@ -298,20 +297,19 @@ gimp_palette_load_act (GimpContext *context,
GList * GList *
gimp_palette_load_riff (GimpContext *context, gimp_palette_load_riff (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error) GError **error)
{ {
GimpPalette *palette; GimpPalette *palette;
gchar *palette_name; gchar *palette_name;
gint fd = fileno (file); gint fd = fileno (f);
guchar color_bytes[4]; guchar color_bytes[4];
g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
palette_name = g_filename_display_basename (filename); palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
palette = GIMP_PALETTE (gimp_palette_new (context, palette_name)); palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
g_free (palette_name); g_free (palette_name);
@ -335,13 +333,13 @@ gimp_palette_load_riff (GimpContext *context,
GList * GList *
gimp_palette_load_psp (GimpContext *context, gimp_palette_load_psp (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error) GError **error)
{ {
GimpPalette *palette; GimpPalette *palette;
gchar *palette_name; gchar *palette_name;
gint fd = fileno (file); gint fd = fileno (f);
guchar color_bytes[4]; guchar color_bytes[4];
gint number_of_colors; gint number_of_colors;
gint data_size; gint data_size;
@ -352,11 +350,10 @@ gimp_palette_load_psp (GimpContext *context,
gchar **lines; gchar **lines;
gchar **ascii_colors; gchar **ascii_colors;
g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
palette_name = g_filename_display_basename (filename); palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
palette = GIMP_PALETTE (gimp_palette_new (context, palette_name)); palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
g_free (palette_name); g_free (palette_name);
@ -373,7 +370,7 @@ gimp_palette_load_psp (GimpContext *context,
if (lines[i + 1] == NULL) if (lines[i + 1] == NULL)
{ {
g_printerr ("Premature end of file reading %s.", g_printerr ("Premature end of file reading %s.",
gimp_filename_to_utf8 (filename)); gimp_file_get_utf8_name (file));
break; break;
} }
@ -385,7 +382,7 @@ gimp_palette_load_psp (GimpContext *context,
if (ascii_colors[j] == NULL) if (ascii_colors[j] == NULL)
{ {
g_printerr ("Corrupted palette file %s.", g_printerr ("Corrupted palette file %s.",
gimp_filename_to_utf8 (filename)); gimp_file_get_utf8_name (file));
color_ok = FALSE; color_ok = FALSE;
break; break;
} }
@ -415,13 +412,13 @@ gimp_palette_load_psp (GimpContext *context,
GList * GList *
gimp_palette_load_aco (GimpContext *context, gimp_palette_load_aco (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error) GError **error)
{ {
GimpPalette *palette; GimpPalette *palette;
gchar *palette_name; gchar *palette_name;
gint fd = fileno (file); gint fd = fileno (f);
gint format_version; gint format_version;
gint number_of_colors; gint number_of_colors;
gint i; gint i;
@ -430,8 +427,7 @@ gimp_palette_load_aco (GimpContext *context,
gchar format2_preamble[4]; gchar format2_preamble[4];
gint status; gint status;
g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
status = read (fd, header, sizeof (header)); status = read (fd, header, sizeof (header));
@ -441,11 +437,11 @@ gimp_palette_load_aco (GimpContext *context,
g_set_error (error, g_set_error (error,
GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Could not read header from palette file '%s'"), _("Could not read header from palette file '%s'"),
gimp_filename_to_utf8 (filename)); gimp_file_get_utf8_name (file));
return NULL; return NULL;
} }
palette_name = g_filename_display_basename (filename); palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
palette = GIMP_PALETTE (gimp_palette_new (context, palette_name)); palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
g_free (palette_name); g_free (palette_name);
@ -463,7 +459,7 @@ gimp_palette_load_aco (GimpContext *context,
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s'"), _("Fatal parse error in palette file '%s'"),
gimp_filename_to_utf8 (filename)); gimp_file_get_utf8_name (file));
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
@ -537,7 +533,7 @@ gimp_palette_load_aco (GimpContext *context,
else else
{ {
g_printerr ("Unsupported color space (%d) in ACO file %s\n", g_printerr ("Unsupported color space (%d) in ACO file %s\n",
color_space, gimp_filename_to_utf8 (filename)); color_space, gimp_file_get_utf8_name (file));
} }
if (format_version == 2) if (format_version == 2)
@ -550,7 +546,7 @@ gimp_palette_load_aco (GimpContext *context,
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s'"), _("Fatal parse error in palette file '%s'"),
gimp_filename_to_utf8 (filename)); gimp_file_get_utf8_name (file));
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
@ -569,8 +565,8 @@ gimp_palette_load_aco (GimpContext *context,
GList * GList *
gimp_palette_load_css (GimpContext *context, gimp_palette_load_css (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error) GError **error)
{ {
GimpPalette *palette; GimpPalette *palette;
@ -578,15 +574,14 @@ gimp_palette_load_css (GimpContext *context,
GRegex *regex; GRegex *regex;
GimpRGB color; GimpRGB color;
g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
regex = g_regex_new (".*color.*:(?P<param>.*);", G_REGEX_CASELESS, 0, error); regex = g_regex_new (".*color.*:(?P<param>.*);", G_REGEX_CASELESS, 0, error);
if (! regex) if (! regex)
return NULL; return NULL;
name = g_filename_display_basename (filename); name = g_path_get_basename (gimp_file_get_utf8_name (file));
palette = GIMP_PALETTE (gimp_palette_new (context, name)); palette = GIMP_PALETTE (gimp_palette_new (context, name));
g_free (name); g_free (name);
@ -595,7 +590,7 @@ gimp_palette_load_css (GimpContext *context,
GMatchInfo *matches; GMatchInfo *matches;
gchar buf[1024]; gchar buf[1024];
if (fgets (buf, sizeof (buf), file) != NULL) if (fgets (buf, sizeof (buf), f) != NULL)
{ {
if (g_regex_match (regex, buf, 0, &matches)) if (g_regex_match (regex, buf, 0, &matches))
{ {
@ -612,7 +607,7 @@ gimp_palette_load_css (GimpContext *context,
g_free (word); g_free (word);
} }
} }
} while (! feof (file)); } while (! feof (f));
g_regex_unref (regex); g_regex_unref (regex);
@ -620,14 +615,14 @@ gimp_palette_load_css (GimpContext *context,
} }
GimpPaletteFileFormat GimpPaletteFileFormat
gimp_palette_load_detect_format (const gchar *filename, gimp_palette_load_detect_format (GFile *file,
FILE *file) FILE *f)
{ {
GimpPaletteFileFormat format = GIMP_PALETTE_FILE_FORMAT_UNKNOWN; GimpPaletteFileFormat format = GIMP_PALETTE_FILE_FORMAT_UNKNOWN;
gint fd = fileno (file); gint fd = fileno (f);
gchar header[16]; gchar header[16];
if (fread (header, 1, sizeof (header), file) == sizeof (header)) if (fread (header, 1, sizeof (header), f) == sizeof (header))
{ {
if (g_str_has_prefix (header + 0, "RIFF") && if (g_str_has_prefix (header + 0, "RIFF") &&
g_str_has_prefix (header + 8, "PAL data")) g_str_has_prefix (header + 8, "PAL data"))
@ -646,7 +641,8 @@ gimp_palette_load_detect_format (const gchar *filename,
if (format == GIMP_PALETTE_FILE_FORMAT_UNKNOWN) if (format == GIMP_PALETTE_FILE_FORMAT_UNKNOWN)
{ {
gchar *lower_filename = g_ascii_strdown (filename, -1); gchar *lower_filename =
g_ascii_strdown (gimp_file_get_utf8_name (file), -1);
if (g_str_has_suffix (lower_filename, ".aco")) if (g_str_has_suffix (lower_filename, ".aco"))
{ {
@ -671,7 +667,7 @@ gimp_palette_load_detect_format (const gchar *filename,
} }
} }
rewind (file); rewind (f);
return format; return format;
} }

View File

@ -38,32 +38,32 @@ GList * gimp_palette_load (GimpContext *context,
GFile *file, GFile *file,
GError **error); GError **error);
GList * gimp_palette_load_gpl (GimpContext *context, GList * gimp_palette_load_gpl (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error); GError **error);
GList * gimp_palette_load_act (GimpContext *context, GList * gimp_palette_load_act (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error); GError **error);
GList * gimp_palette_load_riff (GimpContext *context, GList * gimp_palette_load_riff (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error); GError **error);
GList * gimp_palette_load_psp (GimpContext *context, GList * gimp_palette_load_psp (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error); GError **error);
GList * gimp_palette_load_aco (GimpContext *context, GList * gimp_palette_load_aco (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error); GError **error);
GList * gimp_palette_load_css (GimpContext *context, GList * gimp_palette_load_css (GimpContext *context,
const gchar *filename, GFile *file,
FILE *file, FILE *f,
GError **error); GError **error);
GimpPaletteFileFormat gimp_palette_load_detect_format (const gchar *filename, GimpPaletteFileFormat gimp_palette_load_detect_format (GFile *file,
FILE *file); FILE *f);
#endif /* __GIMP_PALETTE_H__ */ #endif /* __GIMP_PALETTE_H__ */

View File

@ -52,19 +52,17 @@ gimp_palette_save (GimpData *data,
path = g_file_get_path (gimp_data_get_file (data)); path = g_file_get_path (gimp_data_get_file (data));
file = g_fopen (path, "wb"); file = g_fopen (path, "wb");
g_free (path);
if (! file) if (! file)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"), _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (path), gimp_file_get_utf8_name (gimp_data_get_file (data)),
g_strerror (errno)); g_strerror (errno));
g_free (path);
return FALSE; return FALSE;
} }
g_free (path);
fprintf (file, "GIMP Palette\n"); fprintf (file, "GIMP Palette\n");
fprintf (file, "Name: %s\n", gimp_object_get_name (palette)); fprintf (file, "Name: %s\n", gimp_object_get_name (palette));
fprintf (file, "Columns: %d\n#\n", CLAMP (gimp_palette_get_columns (palette), fprintf (file, "Columns: %d\n#\n", CLAMP (gimp_palette_get_columns (palette),

View File

@ -79,12 +79,13 @@ gimp_pattern_load (GimpContext *context,
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
fd = g_open (path, O_RDONLY | _O_BINARY, 0); fd = g_open (path, O_RDONLY | _O_BINARY, 0);
g_free (path);
if (fd == -1) if (fd == -1)
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"), _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (path), g_strerror (errno)); gimp_file_get_utf8_name (file), g_strerror (errno));
g_free (path);
return NULL; return NULL;
} }
@ -94,7 +95,7 @@ gimp_pattern_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': " _("Fatal parse error in pattern file '%s': "
"File appears truncated."), "File appears truncated."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
goto error; goto error;
} }
@ -113,7 +114,7 @@ gimp_pattern_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': " _("Fatal parse error in pattern file '%s': "
"Unknown pattern format version %d."), "Unknown pattern format version %d."),
gimp_filename_to_utf8 (path), header.version); gimp_file_get_utf8_name (file), header.version);
goto error; goto error;
} }
@ -124,7 +125,7 @@ gimp_pattern_load (GimpContext *context,
_("Fatal parse error in pattern file '%s: " _("Fatal parse error in pattern file '%s: "
"Unsupported pattern depth %d.\n" "Unsupported pattern depth %d.\n"
"GIMP Patterns must be GRAY or RGB."), "GIMP Patterns must be GRAY or RGB."),
gimp_filename_to_utf8 (path), header.bytes); gimp_file_get_utf8_name (file), header.bytes);
goto error; goto error;
} }
@ -140,14 +141,14 @@ gimp_pattern_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': " _("Fatal parse error in pattern file '%s': "
"File appears truncated."), "File appears truncated."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
g_free (name); g_free (name);
goto error; goto error;
} }
utf8 = gimp_any_to_utf8 (name, -1, utf8 = gimp_any_to_utf8 (name, -1,
_("Invalid UTF-8 string in pattern file '%s'."), _("Invalid UTF-8 string in pattern file '%s'."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
g_free (name); g_free (name);
name = utf8; name = utf8;
} }
@ -179,12 +180,11 @@ gimp_pattern_load (GimpContext *context,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in pattern file '%s': " _("Fatal parse error in pattern file '%s': "
"File appears truncated."), "File appears truncated."),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
goto error; goto error;
} }
close (fd); close (fd);
g_free (path);
return g_list_prepend (NULL, pattern); return g_list_prepend (NULL, pattern);
@ -193,7 +193,6 @@ gimp_pattern_load (GimpContext *context,
g_object_unref (pattern); g_object_unref (pattern);
close (fd); close (fd);
g_free (path);
return NULL; return NULL;
} }
@ -216,12 +215,10 @@ gimp_pattern_load_pixbuf (GimpContext *context,
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
pixbuf = gdk_pixbuf_new_from_file (path, error); pixbuf = gdk_pixbuf_new_from_file (path, error);
g_free (path);
if (! pixbuf) if (! pixbuf)
{ return NULL;
g_free (path);
return NULL;
}
name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Title")); name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Title"));
@ -229,7 +226,7 @@ gimp_pattern_load_pixbuf (GimpContext *context,
name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Comment")); name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Comment"));
if (! name) if (! name)
name = g_filename_display_basename (path); name = g_path_get_basename (gimp_file_get_utf8_name (file));
pattern = g_object_new (GIMP_TYPE_PATTERN, pattern = g_object_new (GIMP_TYPE_PATTERN,
"name", name, "name", name,
@ -240,7 +237,6 @@ gimp_pattern_load_pixbuf (GimpContext *context,
pattern->mask = gimp_temp_buf_new_from_pixbuf (pixbuf, NULL); pattern->mask = gimp_temp_buf_new_from_pixbuf (pixbuf, NULL);
g_object_unref (pixbuf); g_object_unref (pixbuf);
g_free (path);
return g_list_prepend (NULL, pattern); return g_list_prepend (NULL, pattern);
} }

View File

@ -57,12 +57,9 @@ gimp_tool_preset_load (GimpContext *context,
} }
else else
{ {
gchar *path = g_file_get_path (file);
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE, g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
_("Error while parsing '%s'"), _("Error while parsing '%s'"),
gimp_filename_to_utf8 (path)); gimp_file_get_utf8_name (file));
g_free (path);
} }
} }