Commit 4e6a6079 authored by Michael Natterer's avatar Michael Natterer 😴

app: port levels cruft format saving to GIO

parent 87ecc838
......@@ -659,7 +659,7 @@ gimp_curves_config_save_cruft (GimpCurvesConfig *config,
bytes_written != string->len)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
_("Writing brush file '%s' failed: %s"),
_("Writing curves file '%s' failed: %s"),
gimp_file_get_utf8_name (file),
my_error->message);
g_clear_error (&my_error);
......
......@@ -28,6 +28,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"
......@@ -814,30 +815,64 @@ gimp_levels_config_load_cruft (GimpLevelsConfig *config,
gboolean
gimp_levels_config_save_cruft (GimpLevelsConfig *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_LEVELS_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 Levels 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 Levels File\n");
for (i = 0; i < 5; i++)
{
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
fprintf (file, "%d %d %d %d %s\n",
(gint) (config->low_input[i] * 255.999),
(gint) (config->high_input[i] * 255.999),
(gint) (config->low_output[i] * 255.999),
(gint) (config->high_output[i] * 255.999),
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
config->gamma[i]));
g_string_append_printf (string,
"%d %d %d %d %s\n",
(gint) (config->low_input[i] * 255.999),
(gint) (config->high_input[i] * 255.999),
(gint) (config->low_output[i] * 255.999),
(gint) (config->high_output[i] * 255.999),
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
config->gamma[i]));
}
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 levels 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;
}
......@@ -79,7 +79,7 @@ gboolean gimp_levels_config_load_cruft (GimpLevelsConfig *config,
gpointer fp,
GError **error);
gboolean gimp_levels_config_save_cruft (GimpLevelsConfig *config,
gpointer fp,
GFile *file,
GError **error);
......
......@@ -673,30 +673,7 @@ gimp_levels_tool_settings_export (GimpImageMapTool *image_map_tool,
GimpLevelsTool *tool = GIMP_LEVELS_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_levels_config_save_cruft (tool->config, f, error);
fclose (f);
return success;
}
return gimp_levels_config_save_cruft (tool->config, file, error);
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_export (image_map_tool,
file,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment