mirror of https://github.com/GNOME/gimp.git
app: port curves cruft format saving to GIO
This commit is contained in:
parent
a49709ef6c
commit
87ecc83885
|
@ -27,6 +27,7 @@
|
|||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
#include "libgimpmath/gimpmath.h"
|
||||
#include "libgimpconfig/gimpconfig.h"
|
||||
|
@ -571,17 +572,33 @@ gimp_curves_config_load_cruft (GimpCurvesConfig *config,
|
|||
|
||||
gboolean
|
||||
gimp_curves_config_save_cruft (GimpCurvesConfig *config,
|
||||
gpointer fp,
|
||||
GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
FILE *file = fp;
|
||||
gint i;
|
||||
GOutputStream *output;
|
||||
GString *string;
|
||||
gsize bytes_written;
|
||||
gint i;
|
||||
GError *my_error = NULL;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CURVES_CONFIG (config), FALSE);
|
||||
g_return_val_if_fail (file != NULL, FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
fprintf (file, "# GIMP Curves File\n");
|
||||
output = G_OUTPUT_STREAM (g_file_replace (file,
|
||||
NULL, FALSE, G_FILE_CREATE_NONE,
|
||||
NULL, error));
|
||||
if (! output)
|
||||
{
|
||||
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
|
||||
_("Could not open '%s' for writing: %s"),
|
||||
gimp_file_get_utf8_name (file),
|
||||
my_error->message);
|
||||
g_clear_error (&my_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
string = g_string_new ("# GIMP Curves File\n");
|
||||
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
|
@ -624,18 +641,35 @@ gimp_curves_config_save_cruft (GimpCurvesConfig *config,
|
|||
|
||||
if (x < 0.0 || y < 0.0)
|
||||
{
|
||||
fprintf (file, "%d %d ", -1, -1);
|
||||
g_string_append_printf (string, "%d %d ", -1, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (file, "%d %d ",
|
||||
(gint) (x * 255.999),
|
||||
(gint) (y * 255.999));
|
||||
g_string_append_printf (string, "%d %d ",
|
||||
(gint) (x * 255.999),
|
||||
(gint) (y * 255.999));
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (file, "\n");
|
||||
g_string_append_printf (string, "\n");
|
||||
}
|
||||
|
||||
if (! g_output_stream_write_all (output, string->str, string->len,
|
||||
&bytes_written, NULL, &my_error) ||
|
||||
bytes_written != string->len)
|
||||
{
|
||||
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
|
||||
_("Writing brush file '%s' failed: %s"),
|
||||
gimp_file_get_utf8_name (file),
|
||||
my_error->message);
|
||||
g_clear_error (&my_error);
|
||||
g_string_free (string, TRUE);
|
||||
g_object_unref (output);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_string_free (string, TRUE);
|
||||
g_object_unref (output);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ gboolean gimp_curves_config_load_cruft (GimpCurvesConfig *config,
|
|||
gpointer fp,
|
||||
GError **error);
|
||||
gboolean gimp_curves_config_save_cruft (GimpCurvesConfig *config,
|
||||
gpointer fp,
|
||||
GFile *file,
|
||||
GError **error);
|
||||
|
||||
|
||||
|
|
|
@ -653,30 +653,7 @@ gimp_curves_tool_settings_export (GimpImageMapTool *image_map_tool,
|
|||
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
|
||||
|
||||
if (tool->export_old_format)
|
||||
{
|
||||
gchar *path;
|
||||
FILE *f;
|
||||
gboolean success;
|
||||
|
||||
path = g_file_get_path (file);
|
||||
f = g_fopen (path, "wt");
|
||||
g_free (path);
|
||||
|
||||
if (! f)
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Could not open '%s' for writing: %s"),
|
||||
gimp_file_get_utf8_name (file),
|
||||
g_strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
success = gimp_curves_config_save_cruft (tool->config, f, error);
|
||||
|
||||
fclose (f);
|
||||
|
||||
return success;
|
||||
}
|
||||
return gimp_curves_config_save_cruft (tool->config, file, error);
|
||||
|
||||
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_export (image_map_tool,
|
||||
file,
|
||||
|
|
Loading…
Reference in New Issue