gimp r27195 - in branches/gimp-2-6: . app/core app/tools app/widgets



Author: mitch
Date: Thu Oct  9 15:32:24 2008
New Revision: 27195
URL: http://svn.gnome.org/viewvc/gimp?rev=27195&view=rev

Log:
2008-10-09  Michael Natterer  <mitch gimp org>

	Merged from trunk:

	This is not exactly a bugfix-only commit, but fixing this bug
	was the original reason for all the curve and image map tool
	refactorings that went into 2.6. It would be silly not to
	fix it just because I simply forgot to hack the final step of
	enabling all the new code. The two new translatable strings are
	a PITA, sorry about that; but better than still only exporting
	the old curves and levels formats in 2.6.

	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.



Modified:
   branches/gimp-2-6/ChangeLog
   branches/gimp-2-6/app/core/gimpmarshal.list
   branches/gimp-2-6/app/tools/gimpcurvestool.c
   branches/gimp-2-6/app/tools/gimpcurvestool.h
   branches/gimp-2-6/app/tools/gimplevelstool.c
   branches/gimp-2-6/app/tools/gimplevelstool.h
   branches/gimp-2-6/app/widgets/gimpsettingsbox.c
   branches/gimp-2-6/app/widgets/gimpsettingsbox.h

Modified: branches/gimp-2-6/app/core/gimpmarshal.list
==============================================================================
--- branches/gimp-2-6/app/core/gimpmarshal.list	(original)
+++ branches/gimp-2-6/app/core/gimpmarshal.list	Thu Oct  9 15:32:24 2008
@@ -44,6 +44,7 @@
 VOID: INT, INT
 VOID: INT, INT, INT, INT
 VOID: OBJECT
+VOID: OBJECT, BOOLEAN
 VOID: OBJECT, INT
 VOID: OBJECT, OBJECT
 VOID: OBJECT, POINTER

Modified: branches/gimp-2-6/app/tools/gimpcurvestool.c
==============================================================================
--- branches/gimp-2-6/app/tools/gimpcurvestool.c	(original)
+++ branches/gimp-2-6/app/tools/gimpcurvestool.c	Thu Oct  9 15:32:24 2008
@@ -101,6 +101,10 @@
                                                    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 @@
   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 @@
 {
   GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
   FILE           *file;
-  gboolean        success;
   gchar           header[64];
 
   file = g_fopen (filename, "rt");
@@ -631,6 +638,8 @@
 
   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 @@
                                   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

Modified: branches/gimp-2-6/app/tools/gimpcurvestool.h
==============================================================================
--- branches/gimp-2-6/app/tools/gimpcurvestool.h	(original)
+++ branches/gimp-2-6/app/tools/gimpcurvestool.h	Thu Oct  9 15:32:24 2008
@@ -48,6 +48,9 @@
   GtkWidget            *yrange;
   GtkWidget            *graph;
   GtkWidget            *curve_type;
+
+  /* export dialog */
+  gboolean              export_old_format;
 };
 
 struct _GimpCurvesToolClass

Modified: branches/gimp-2-6/app/tools/gimplevelstool.c
==============================================================================
--- branches/gimp-2-6/app/tools/gimplevelstool.c	(original)
+++ branches/gimp-2-6/app/tools/gimplevelstool.c	Thu Oct  9 15:32:24 2008
@@ -94,6 +94,10 @@
                                                    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 @@
   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 @@
 {
   GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
   FILE           *file;
-  gboolean        success;
+  gchar           header[64];
 
   file = g_fopen (filename, "rt");
 
@@ -738,11 +746,34 @@
       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 @@
                                   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

Modified: branches/gimp-2-6/app/tools/gimplevelstool.h
==============================================================================
--- branches/gimp-2-6/app/tools/gimplevelstool.h	(original)
+++ branches/gimp-2-6/app/tools/gimplevelstool.h	Thu Oct  9 15:32:24 2008
@@ -61,6 +61,9 @@
   GtkAdjustment        *high_output;
 
   GtkWidget            *active_picker;
+
+  /* export dialog */
+  gboolean              export_old_format;
 };
 
 struct _GimpLevelsToolClass

Modified: branches/gimp-2-6/app/widgets/gimpsettingsbox.c
==============================================================================
--- branches/gimp-2-6/app/widgets/gimpsettingsbox.c	(original)
+++ branches/gimp-2-6/app/widgets/gimpsettingsbox.c	Thu Oct  9 15:32:24 2008
@@ -44,6 +44,7 @@
 
 enum
 {
+  FILE_DIALOG_SETUP,
   IMPORT,
   EXPORT,
   LAST_SIGNAL
@@ -127,6 +128,17 @@
 {
   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 @@
   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_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);
 }
 

Modified: branches/gimp-2-6/app/widgets/gimpsettingsbox.h
==============================================================================
--- branches/gimp-2-6/app/widgets/gimpsettingsbox.h	(original)
+++ branches/gimp-2-6/app/widgets/gimpsettingsbox.h	Thu Oct  9 15:32:24 2008
@@ -60,10 +60,13 @@
 {
   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);
 };
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]