Commit e21935a7 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Bug 134956 – Curves tool doesn't save free curves

2008-10-09  Michael Natterer  <mitch@gimp.org>

	Bug 134956 – Curves tool doesn't save free curves

	* app/core/gimpmarshal.list
	* app/widgets/gimpsettingsbox.[ch]: add signal "file-dialog-setup"
	and emit it when the export/import file chooser is fully
	constructed. Callbacks can then do additional things to the
	dialog, like adding custom buttons.

	* app/tools/gimpcurvestool.h
	* app/tools/gimplevelstool.h: add boolean member
	"export_old_format".

	* app/tools/gimpcurvestool.c
	* app/tools/gimplevelstool.c (gimp_*_tool_dialog): connect to
	the settings box' "file-dialog-setup".

	(gimp_*_tool_export_setup): new callback which adds a toggle to
	the file choosers that allows to export to the old format.
	Default saving the new format, we defaulted to the old one before.

	(gimp_*_tool_settings_export): check the "export_old_format"
	boolean and only save the cruft format if it is TRUE; chain up
	otherwise, which generically saves the new format.

	* app/tools/gimplevelstool.c (gimp_levels_tool_settings_import):
	add the same file format detection code as in the curves tool
	so it transparently loads old and new levels files.


svn path=/trunk/; revision=27194
parent 176c24be
2008-10-09 Michael Natterer <mitch@gimp.org>
Bug 134956 – Curves tool doesn't save free curves
* app/core/gimpmarshal.list
* app/widgets/gimpsettingsbox.[ch]: add signal "file-dialog-setup"
and emit it when the export/import file chooser is fully
constructed. Callbacks can then do additional things to the
dialog, like adding custom buttons.
* app/tools/gimpcurvestool.h
* app/tools/gimplevelstool.h: add boolean member
"export_old_format".
* app/tools/gimpcurvestool.c
* app/tools/gimplevelstool.c (gimp_*_tool_dialog): connect to
the settings box' "file-dialog-setup".
(gimp_*_tool_export_setup): new callback which adds a toggle to
the file choosers that allows to export to the old format.
Default saving the new format, we defaulted to the old one before.
(gimp_*_tool_settings_export): check the "export_old_format"
boolean and only save the cruft format if it is TRUE; chain up
otherwise, which generically saves the new format.
* app/tools/gimplevelstool.c (gimp_levels_tool_settings_import):
add the same file format detection code as in the curves tool
so it transparently loads old and new levels files.
2008-10-09 Sven Neumann <sven@gimp.org>
* app/core/gimp-user-install.c (gimp_user_install_detect_old):
......
......@@ -44,6 +44,7 @@ VOID: INT
VOID: INT, INT
VOID: INT, INT, INT, INT
VOID: OBJECT
VOID: OBJECT, BOOLEAN
VOID: OBJECT, INT
VOID: OBJECT, OBJECT
VOID: OBJECT, POINTER
......
......@@ -101,6 +101,10 @@ static gboolean gimp_curves_tool_settings_export(GimpImageMapTool *image_m
const gchar *filename,
GError **error);
static void gimp_curves_tool_export_setup (GimpSettingsBox *settings_box,
GtkFileChooserDialog *dialog,
gboolean export,
GimpCurvesTool *tool);
static void gimp_curves_tool_config_notify (GObject *object,
GParamSpec *pspec,
GimpCurvesTool *tool);
......@@ -422,6 +426,10 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
GtkWidget *bar;
GtkWidget *combo;
g_signal_connect (image_map_tool->settings_box, "file-dialog-setup",
G_CALLBACK (gimp_curves_tool_export_setup),
image_map_tool);
main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool);
label_group = gimp_image_map_tool_dialog_get_label_group (image_map_tool);
......@@ -605,7 +613,6 @@ gimp_curves_tool_settings_import (GimpImageMapTool *image_map_tool,
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
FILE *file;
gboolean success;
gchar header[64];
file = g_fopen (filename, "rt");
......@@ -631,6 +638,8 @@ gimp_curves_tool_settings_import (GimpImageMapTool *image_map_tool,
if (g_str_has_prefix (header, "# GIMP Curves File\n"))
{
gboolean success;
rewind (file);
success = gimp_curves_config_load_cruft (tool->config, file, error);
......@@ -653,25 +662,55 @@ gimp_curves_tool_settings_export (GimpImageMapTool *image_map_tool,
GError **error)
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
FILE *file;
gboolean success;
file = g_fopen (filename, "wt");
if (! file)
if (tool->export_old_format)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename),
g_strerror (errno));
return FALSE;
FILE *file;
gboolean success;
file = g_fopen (filename, "wt");
if (! file)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename),
g_strerror (errno));
return FALSE;
}
success = gimp_curves_config_save_cruft (tool->config, file, error);
fclose (file);
return success;
}
success = gimp_curves_config_save_cruft (tool->config, file, error);
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_export (image_map_tool,
filename,
error);
}
static void
gimp_curves_tool_export_setup (GimpSettingsBox *settings_box,
GtkFileChooserDialog *dialog,
gboolean export,
GimpCurvesTool *tool)
{
GtkWidget *button;
fclose (file);
if (! export)
return;
button = gtk_check_button_new_with_mnemonic (_("Use _old curves file format"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
tool->export_old_format);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), button);
gtk_widget_show (button);
return success;
g_signal_connect (button, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&tool->export_old_format);
}
static void
......
......@@ -48,6 +48,9 @@ struct _GimpCurvesTool
GtkWidget *yrange;
GtkWidget *graph;
GtkWidget *curve_type;
/* export dialog */
gboolean export_old_format;
};
struct _GimpCurvesToolClass
......
......@@ -94,6 +94,10 @@ static gboolean gimp_levels_tool_settings_export(GimpImageMapTool *im_tool,
const gchar *filename,
GError **error);
static void gimp_levels_tool_export_setup (GimpSettingsBox *settings_box,
GtkFileChooserDialog *dialog,
gboolean export,
GimpLevelsTool *tool);
static void gimp_levels_tool_config_notify (GObject *object,
GParamSpec *pspec,
GimpLevelsTool *tool);
......@@ -361,6 +365,10 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool)
GtkObject *data;
gint border;
g_signal_connect (image_map_tool->settings_box, "file-dialog-setup",
G_CALLBACK (gimp_levels_tool_export_setup),
image_map_tool);
main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool);
label_group = gimp_image_map_tool_dialog_get_label_group (image_map_tool);
......@@ -725,7 +733,7 @@ gimp_levels_tool_settings_import (GimpImageMapTool *image_map_tool,
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
FILE *file;
gboolean success;
gchar header[64];
file = g_fopen (filename, "rt");
......@@ -738,11 +746,34 @@ gimp_levels_tool_settings_import (GimpImageMapTool *image_map_tool,
return FALSE;
}
success = gimp_levels_config_load_cruft (tool->config, file, error);
if (! fgets (header, sizeof (header), file))
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not read header from '%s': %s"),
gimp_filename_to_utf8 (filename),
g_strerror (errno));
fclose (file);
return FALSE;
}
if (g_str_has_prefix (header, "# GIMP Levels File\n"))
{
gboolean success;
rewind (file);
success = gimp_levels_config_load_cruft (tool->config, file, error);
fclose (file);
return success;
}
fclose (file);
return success;
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_import (image_map_tool,
filename,
error);
}
static gboolean
......@@ -751,25 +782,55 @@ gimp_levels_tool_settings_export (GimpImageMapTool *image_map_tool,
GError **error)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
FILE *file;
gboolean success;
file = g_fopen (filename, "wt");
if (! file)
if (tool->export_old_format)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename),
g_strerror (errno));
return FALSE;
FILE *file;
gboolean success;
file = g_fopen (filename, "wt");
if (! file)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename),
g_strerror (errno));
return FALSE;
}
success = gimp_levels_config_save_cruft (tool->config, file, error);
fclose (file);
return success;
}
success = gimp_levels_config_save_cruft (tool->config, file, error);
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_export (image_map_tool,
filename,
error);
}
fclose (file);
static void
gimp_levels_tool_export_setup (GimpSettingsBox *settings_box,
GtkFileChooserDialog *dialog,
gboolean export,
GimpLevelsTool *tool)
{
GtkWidget *button;
return success;
if (! export)
return;
button = gtk_check_button_new_with_mnemonic (_("Use _old levels file format"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
tool->export_old_format);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), button);
gtk_widget_show (button);
g_signal_connect (button, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&tool->export_old_format);
}
static void
......
......@@ -61,6 +61,9 @@ struct _GimpLevelsTool
GtkAdjustment *high_output;
GtkWidget *active_picker;
/* export dialog */
gboolean export_old_format;
};
struct _GimpLevelsToolClass
......
......@@ -44,6 +44,7 @@
enum
{
FILE_DIALOG_SETUP,
IMPORT,
EXPORT,
LAST_SIGNAL
......@@ -127,6 +128,17 @@ gimp_settings_box_class_init (GimpSettingsBoxClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
settings_box_signals[FILE_DIALOG_SETUP] =
g_signal_new ("file-dialog-setup",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GimpSettingsBoxClass, file_dialog_setup),
NULL, NULL,
gimp_marshal_VOID__OBJECT_BOOLEAN,
G_TYPE_NONE, 2,
GTK_TYPE_FILE_CHOOSER_DIALOG,
G_TYPE_BOOLEAN);
settings_box_signals[IMPORT] =
g_signal_new ("import",
G_TYPE_FROM_CLASS (klass),
......@@ -152,6 +164,7 @@ gimp_settings_box_class_init (GimpSettingsBoxClass *klass)
object_class->set_property = gimp_settings_box_set_property;
object_class->get_property = gimp_settings_box_get_property;
klass->file_dialog_setup = NULL;
klass->import = NULL;
klass->export = NULL;
......@@ -741,6 +754,10 @@ gimp_settings_box_file_dialog (GimpSettingsBox *box,
gimp_help_connect (box->file_dialog, gimp_standard_help_func,
box->file_dialog_help_id, NULL);
/* allow callbacks to add widgets to the dialog */
g_signal_emit (box, settings_box_signals[FILE_DIALOG_SETUP], 0,
box->file_dialog, save);
gtk_widget_show (box->file_dialog);
}
......
......@@ -60,10 +60,13 @@ struct _GimpSettingsBoxClass
{
GtkHBoxClass parent_class;
void (* import) (GimpSettingsBox *box,
const gchar *filename);
void (* export) (GimpSettingsBox *box,
const gchar *filename);
void (* file_dialog_setup) (GimpSettingsBox *box,
GtkFileChooserDialog *dialog,
gboolean export);
void (* import) (GimpSettingsBox *box,
const gchar *filename);
void (* export) (GimpSettingsBox *box,
const gchar *filename);
};
......
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