app: port levels cruft format saving to GIO
This commit is contained in:
@ -659,7 +659,7 @@ gimp_curves_config_save_cruft (GimpCurvesConfig *config,
|
|||||||
bytes_written != string->len)
|
bytes_written != string->len)
|
||||||
{
|
{
|
||||||
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
|
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),
|
gimp_file_get_utf8_name (file),
|
||||||
my_error->message);
|
my_error->message);
|
||||||
g_clear_error (&my_error);
|
g_clear_error (&my_error);
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
|
|
||||||
|
#include "libgimpbase/gimpbase.h"
|
||||||
#include "libgimpcolor/gimpcolor.h"
|
#include "libgimpcolor/gimpcolor.h"
|
||||||
#include "libgimpmath/gimpmath.h"
|
#include "libgimpmath/gimpmath.h"
|
||||||
#include "libgimpconfig/gimpconfig.h"
|
#include "libgimpconfig/gimpconfig.h"
|
||||||
@ -814,30 +815,64 @@ gimp_levels_config_load_cruft (GimpLevelsConfig *config,
|
|||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gimp_levels_config_save_cruft (GimpLevelsConfig *config,
|
gimp_levels_config_save_cruft (GimpLevelsConfig *config,
|
||||||
gpointer fp,
|
GFile *file,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
FILE *file = fp;
|
GOutputStream *output;
|
||||||
gint i;
|
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 (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);
|
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++)
|
for (i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
||||||
|
|
||||||
fprintf (file, "%d %d %d %d %s\n",
|
g_string_append_printf (string,
|
||||||
(gint) (config->low_input[i] * 255.999),
|
"%d %d %d %d %s\n",
|
||||||
(gint) (config->high_input[i] * 255.999),
|
(gint) (config->low_input[i] * 255.999),
|
||||||
(gint) (config->low_output[i] * 255.999),
|
(gint) (config->high_input[i] * 255.999),
|
||||||
(gint) (config->high_output[i] * 255.999),
|
(gint) (config->low_output[i] * 255.999),
|
||||||
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
(gint) (config->high_output[i] * 255.999),
|
||||||
config->gamma[i]));
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ gboolean gimp_levels_config_load_cruft (GimpLevelsConfig *config,
|
|||||||
gpointer fp,
|
gpointer fp,
|
||||||
GError **error);
|
GError **error);
|
||||||
gboolean gimp_levels_config_save_cruft (GimpLevelsConfig *config,
|
gboolean gimp_levels_config_save_cruft (GimpLevelsConfig *config,
|
||||||
gpointer fp,
|
GFile *file,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
|
||||||
|
@ -673,30 +673,7 @@ gimp_levels_tool_settings_export (GimpImageMapTool *image_map_tool,
|
|||||||
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
|
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
|
||||||
|
|
||||||
if (tool->export_old_format)
|
if (tool->export_old_format)
|
||||||
{
|
return gimp_levels_config_save_cruft (tool->config, file, error);
|
||||||
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_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_export (image_map_tool,
|
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_export (image_map_tool,
|
||||||
file,
|
file,
|
||||||
|
Reference in New Issue
Block a user