app: more filename -> GFile

This commit is contained in:
Michael Natterer 2014-07-01 15:56:39 +02:00
parent a31cb02405
commit 651c3d56ff
9 changed files with 56 additions and 46 deletions

View file

@ -123,19 +123,22 @@ gradients_save_as_pov_ray_response (GtkWidget *dialog,
{
if (response_id == GTK_RESPONSE_OK)
{
const gchar *filename;
GError *error = NULL;
GFile *file;
GError *error = NULL;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
if (! gimp_gradient_save_pov (gradient, filename, &error))
if (! gimp_gradient_save_pov (gradient, file, &error))
{
gimp_message_literal (g_object_get_data (G_OBJECT (dialog), "gimp"),
G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
g_object_unref (file);
return;
}
g_object_unref (file);
}
gtk_widget_destroy (dialog);

View file

@ -38,28 +38,33 @@
GList *
gimp_curve_load (const gchar *filename,
GError **error)
gimp_curve_load (GFile *file,
GError **error)
{
FILE *file;
gchar *path;
FILE *f;
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");
f = g_fopen (path, "rb");
g_free (path);
if (! file)
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_file_get_utf8_name (file), g_strerror (errno));
return NULL;
}
/* load curves */
fclose (file);
fclose (f);
return NULL;
}

View file

@ -22,8 +22,8 @@
#define GIMP_CURVE_FILE_EXTENSION ".curve"
GList * gimp_curve_load (const gchar *filename,
GError **error);
GList * gimp_curve_load (GFile *file,
GError **error);
#endif /* __GIMP_CURVE_LOAD_H__ */

View file

@ -390,7 +390,7 @@ gimp_data_factory_data_refresh (GimpDataFactory *factory,
gimp_data_factory_data_foreach (factory, TRUE,
gimp_data_factory_refresh_cache_add, cache);
/* Now the cache contains a filename => list-of-objects mapping of
/* Now the cache contains a GFile => list-of-objects mapping of
* the old objects. So we should now traverse the directory and for
* each file load it only if its mtime is newer.
*

View file

@ -128,33 +128,36 @@ gimp_gradient_save (GimpData *data,
gboolean
gimp_gradient_save_pov (GimpGradient *gradient,
const gchar *filename,
GFile *file,
GError **error)
{
FILE *file;
gchar *path;
FILE *f;
GimpGradientSegment *seg;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
gchar color_buf[4][G_ASCII_DTOSTR_BUF_SIZE];
g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
file = g_fopen (filename, "wb");
path = g_file_get_path (file);
f = g_fopen (path, "wb");
g_free (path);
if (! file)
if (! f)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_file_get_utf8_name (file), g_strerror (errno));
return FALSE;
}
else
{
fprintf (file, "/* color_map file created by GIMP */\n");
fprintf (file, "/* http://www.gimp.org/ */\n");
fprintf (f, "/* color_map file created by GIMP */\n");
fprintf (f, "/* http://www.gimp.org/ */\n");
fprintf (file, "color_map {\n");
fprintf (f, "color_map {\n");
for (seg = gradient->segments; seg; seg = seg->next)
{
@ -170,7 +173,7 @@ gimp_gradient_save_pov (GimpGradient *gradient,
g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f",
1.0 - seg->left_color.a);
fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
fprintf (f, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
buf,
color_buf[0], color_buf[1], color_buf[2], color_buf[3]);
@ -186,7 +189,7 @@ gimp_gradient_save_pov (GimpGradient *gradient,
g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f",
1.0 - (seg->left_color.a + seg->right_color.a) / 2.0);
fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
fprintf (f, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
buf,
color_buf[0], color_buf[1], color_buf[2], color_buf[3]);
@ -202,13 +205,13 @@ gimp_gradient_save_pov (GimpGradient *gradient,
g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f",
1.0 - seg->right_color.a);
fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
fprintf (f, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
buf,
color_buf[0], color_buf[1], color_buf[2], color_buf[3]);
}
fprintf (file, "} /* color_map */\n");
fclose (file);
fprintf (f, "} /* color_map */\n");
fclose (f);
}
return TRUE;

View file

@ -24,7 +24,7 @@ gboolean gimp_gradient_save (GimpData *data,
GError **error);
gboolean gimp_gradient_save_pov (GimpGradient *gradient,
const gchar *filename,
GFile *file,
GError **error);

View file

@ -494,30 +494,31 @@ gimp_palette_import_from_drawable (GimpDrawable *drawable,
GimpPalette *
gimp_palette_import_from_file (GimpContext *context,
const gchar *filename,
GFile *file,
const gchar *palette_name,
GError **error)
{
GList *palette_list = NULL;
GFile *file;
gchar *path;
FILE *f;
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (palette_name != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
f = g_fopen (filename, "rb");
path = g_file_get_path (file);
f = g_fopen (path, "rb");
g_free (path);
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_file_get_utf8_name (file), g_strerror (errno));
return NULL;
}
file = g_file_new_for_path (filename);
switch (gimp_palette_load_detect_format (file, f))
{
case GIMP_PALETTE_FILE_FORMAT_GPL:
@ -548,11 +549,10 @@ gimp_palette_import_from_file (GimpContext *context,
g_set_error (error,
GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Unknown type of palette file: %s"),
gimp_filename_to_utf8 (filename));
gimp_file_get_utf8_name (file));
break;
}
g_object_unref (file);
fclose (f);
if (palette_list)

View file

@ -40,7 +40,7 @@ GimpPalette * gimp_palette_import_from_drawable (GimpDrawable *drawable,
gint threshold,
gboolean selection_only);
GimpPalette * gimp_palette_import_from_file (GimpContext *context,
const gchar *filename,
GFile *file,
const gchar *palette_name,
GError **error);

View file

@ -837,16 +837,15 @@ palette_import_make_palette (ImportDialog *dialog)
case FILE_IMPORT:
{
gchar *filename;
GFile *file;
GError *error = NULL;
filename =
gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog->file_chooser));
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog->file_chooser));
palette = gimp_palette_import_from_file (dialog->context,
filename,
file,
palette_name, &error);
g_free (filename);
g_object_unref (file);
if (! palette)
{