Index: jpeg-save.c
===================================================================
--- jpeg-save.c	(révision 22857)
+++ jpeg-save.c	(copie de travail)
@@ -699,6 +699,7 @@
 gboolean
 save_dialog (void)
 {
+  JpegSaveGui   pg;
   GtkWidget     *dialog;
   GtkWidget     *vbox;
   GtkObject     *entry;
@@ -708,7 +709,7 @@
   GtkWidget     *frame;
   GtkWidget     *toggle;
   GtkWidget     *spinbutton;
-  GtkObject     *scale_data;
+  //GtkObject     *scale_data;
   GtkWidget     *ebox;
   GtkWidget     *label;
   GtkWidget     *combo;
@@ -720,19 +721,24 @@
   gchar         *text;
   gboolean       run;
 
+
   dialog = gimp_dialog_new (_("Save as JPEG"), PLUG_IN_BINARY,
                             NULL, 0,
                             gimp_standard_help_func, SAVE_PROC,
 
+									 _("_Load defaults"), RESPONSE_LOAD_DEFAULTS,
+									 _("_Save defaults"), RESPONSE_SAVE_DEFAULTS,
                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                             GTK_STOCK_SAVE,   GTK_RESPONSE_OK,
 
                             NULL);
 
-  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
-                                           GTK_RESPONSE_OK,
-                                           GTK_RESPONSE_CANCEL,
-                                           -1);
+  g_signal_connect (dialog, "response",
+                    G_CALLBACK (save_dialog_response),
+                    &pg);
+	g_signal_connect (dialog, "destroy",
+                    G_CALLBACK (gtk_main_quit),
+                    NULL);
 
   gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
   gimp_window_set_transient (GTK_WINDOW (dialog));
@@ -747,7 +753,7 @@
   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
   gtk_widget_show (table);
 
-  entry = gimp_scale_entry_new (GTK_TABLE (table), 0, 0, _("_Quality:"),
+  pg.quality = entry = gimp_scale_entry_new (GTK_TABLE (table), 0, 0, _("_Quality:"),
                                 SCALE_WIDTH, 0, jsvals.quality,
                                 0.0, 100.0, 1.0, 10.0, 0,
                                 TRUE, 0.0, 0.0,
@@ -776,7 +782,7 @@
   gtk_container_add (GTK_CONTAINER (ebox), preview_size);
   gtk_widget_show (preview_size);
 
-  toggle =
+  pg.preview = toggle =
     gtk_check_button_new_with_mnemonic (_("Show _preview in image window"));
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), jsvals.preview);
   gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
@@ -817,7 +823,7 @@
                     2, 6, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
   gtk_widget_show (table2);
 
-  entry = gimp_scale_entry_new (GTK_TABLE (table2), 0, 0, _("_Smoothing:"),
+  pg.smoothing = entry = gimp_scale_entry_new (GTK_TABLE (table2), 0, 0, _("_Smoothing:"),
                                 100, 0, jsvals.smoothing,
                                 0.0, 1.0, 0.01, 0.1, 2,
                                 TRUE, 0.0, 0.0,
@@ -836,15 +842,16 @@
                     GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
   gtk_widget_show (restart_markers_label);
 
-  restart_markers_scale = spinbutton =
-    gimp_spin_button_new (&scale_data,
+  //pg.scale_data = scale_data;
+  pg.restart = restart_markers_scale = spinbutton =
+    gimp_spin_button_new (&pg.scale_data,
                           (jsvals.restart == 0) ? 1 : jsvals.restart,
                           1.0, 64.0, 1.0, 1.0, 64.0, 1.0, 0);
   gtk_table_attach (GTK_TABLE (table), spinbutton, 5, 6, 1, 2,
                     GTK_FILL, GTK_FILL, 0, 0);
   gtk_widget_show (spinbutton);
 
-  toggle = gtk_check_button_new_with_label (_("Use restart markers"));
+  pg.use_restart_markers = toggle = gtk_check_button_new_with_label (_("Use restart markers"));
   gtk_table_attach (GTK_TABLE (table), toggle, 2, 4, 1, 2, GTK_FILL, 0, 0, 0);
   gtk_widget_show (toggle);
 
@@ -853,14 +860,14 @@
   gtk_widget_set_sensitive (restart_markers_label, jsvals.restart);
   gtk_widget_set_sensitive (restart_markers_scale, jsvals.restart);
 
-  g_signal_connect (scale_data, "value-changed",
+  g_signal_connect (pg.scale_data, "value-changed",
                     G_CALLBACK (save_restart_update),
                     toggle);
-  g_signal_connect_swapped (toggle, "toggled",
+  pg.handler_id_restart = g_signal_connect_swapped (toggle, "toggled",
                             G_CALLBACK (save_restart_update),
-                            scale_data);
+                            pg.scale_data);
 
-  toggle = gtk_check_button_new_with_label (_("Optimize"));
+  pg.optimize = toggle = gtk_check_button_new_with_label (_("Optimize"));
   gtk_table_attach (GTK_TABLE (table), toggle, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
   gtk_widget_show (toggle);
 
@@ -873,7 +880,7 @@
 
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), jsvals.optimize);
 
-  toggle = gtk_check_button_new_with_label (_("Progressive"));
+  pg.progressive = toggle = gtk_check_button_new_with_label (_("Progressive"));
   gtk_table_attach (GTK_TABLE (table), toggle, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
   gtk_widget_show (toggle);
 
@@ -887,7 +894,7 @@
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
                                 jsvals.progressive);
 
-  toggle = gtk_check_button_new_with_label (_("Force baseline JPEG"));
+  pg.baseline = toggle = gtk_check_button_new_with_label (_("Force baseline JPEG"));
   gtk_table_attach (GTK_TABLE (table), toggle, 0, 1, 2, 3, GTK_FILL, 0, 0, 0);
   gtk_widget_show (toggle);
 
@@ -902,7 +909,7 @@
                                 jsvals.baseline);
 
 #ifdef HAVE_EXIF
-  toggle = gtk_check_button_new_with_label (_("Save EXIF data"));
+  pg.save_exif = toggle = gtk_check_button_new_with_label (_("Save EXIF data"));
   gtk_table_attach (GTK_TABLE (table), toggle, 0, 1, 3, 4, GTK_FILL, 0, 0, 0);
   gtk_widget_show (toggle);
 
@@ -918,7 +925,7 @@
 
   gtk_widget_set_sensitive (toggle, exif_data != NULL);
 
-  toggle = gtk_check_button_new_with_label (_("Save thumbnail"));
+  pg.save_thumbnail = toggle = gtk_check_button_new_with_label (_("Save thumbnail"));
   gtk_table_attach (GTK_TABLE (table), toggle, 0, 1, 4, 5, GTK_FILL, 0, 0, 0);
   gtk_widget_show (toggle);
 
@@ -934,7 +941,7 @@
 #endif /* HAVE_EXIF */
 
   /* XMP metadata */
-  toggle = gtk_check_button_new_with_label (_("Save XMP data"));
+  pg.save_xmp = toggle = gtk_check_button_new_with_label (_("Save XMP data"));
   gtk_table_attach (GTK_TABLE (table), toggle, 0, 1, 5, 6, GTK_FILL, 0, 0, 0);
   gtk_widget_show (toggle);
 
@@ -953,7 +960,7 @@
                     GTK_FILL, GTK_FILL, 0, 0);
   gtk_widget_show (label);
 
-  combo = gimp_int_combo_box_new ("2x2,1x1,1x1",         0,
+  pg.subsmp = combo = gimp_int_combo_box_new ("2x2,1x1,1x1",         0,
                                   "2x1,1x1,1x1 (4:2:2)", 1,
                                   "1x1,1x1,1x1",         2,
                                   NULL);
@@ -976,7 +983,7 @@
                     GTK_FILL, GTK_FILL, 0, 0);
   gtk_widget_show (label);
 
-  combo = gimp_int_combo_box_new (_("Fast Integer"),   1,
+  pg.dct = combo = gimp_int_combo_box_new (_("Fast Integer"),   1,
                                   _("Integer"),        0,
                                   _("Floating-Point"), 2,
                                   NULL);
@@ -1006,7 +1013,7 @@
   gtk_container_add (GTK_CONTAINER (frame), scrolled_window);
   gtk_widget_show (scrolled_window);
 
-  text_buffer = gtk_text_buffer_new (NULL);
+  pg.text_buffer = text_buffer = gtk_text_buffer_new (NULL);
   if (image_comment)
     gtk_text_buffer_set_text (text_buffer, image_comment, -1);
 
@@ -1025,27 +1032,158 @@
 
   make_preview ();
 
-  run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
+  pg.run = FALSE;
+  gtk_main ();
+  
+  return pg.run;
+}
 
-  if (run)
+static void
+save_dialog_response (GtkWidget *widget,
+                      gint       response_id,
+                      gpointer   data)
+{
+  JpegSaveGui *pg = data;
+  GtkTextIter start_iter;
+  GtkTextIter end_iter;
+
+  switch (response_id)
     {
-      GtkTextIter start_iter;
-      GtkTextIter end_iter;
+    case RESPONSE_LOAD_DEFAULTS:
+      load_gui_defaults (pg);
+      break;
 
-      gtk_text_buffer_get_bounds (text_buffer, &start_iter, &end_iter);
-      image_comment = gtk_text_buffer_get_text (text_buffer,
+    case RESPONSE_SAVE_DEFAULTS:
+      save_defaults ();
+      break;
+
+    case GTK_RESPONSE_OK:
+      gtk_text_buffer_get_bounds (pg->text_buffer, &start_iter, &end_iter);
+      image_comment = gtk_text_buffer_get_text (pg->text_buffer,
                                                 &start_iter, &end_iter, FALSE);
+      pg->run = TRUE;
+
+    default:
+      gtk_widget_destroy (widget);
+      break;
     }
+}
 
-  gtk_widget_destroy (dialog);
+gboolean
+load_defaults (void)
+{
+  GimpParasite *parasite;
+  gchar        *def_str;
+  JpegSaveVals   tmpvals;
+  gint          num_fields;
 
-  destroy_preview ();
-  gimp_displays_flush ();
+  parasite = gimp_parasite_find (JPEG_DEFAULTS_PARASITE);
 
-  return run;
+  if (! parasite)
+    return FALSE;
+
+  def_str = g_strndup (gimp_parasite_data (parasite),
+                       gimp_parasite_data_size (parasite));
+
+  gimp_parasite_free (parasite);
+
+  num_fields = sscanf (def_str, "%lf %lf %d %d %d %d %d %d %d %d %d %d",
+                       &tmpvals.quality,
+                       &tmpvals.smoothing,
+							  &tmpvals.optimize,
+                       &tmpvals.progressive,
+                       &tmpvals.subsmp,
+                       &tmpvals.baseline,
+                       &tmpvals.restart,
+                       &tmpvals.dct,
+                       &tmpvals.preview,
+                       &tmpvals.save_exif,
+					   	  &tmpvals.save_thumbnail,
+							  &tmpvals.save_xmp);
+  if (num_fields == 12)
+    {
+      memcpy (&jsvals, &tmpvals, sizeof (tmpvals));
+      return TRUE;
+    }
+  else
+    {
+      return FALSE;
+    }
 }
 
 static void
+save_defaults (void)
+{
+  GimpParasite *parasite;
+  gchar        *def_str;
+
+  def_str = g_strdup_printf ("%lf %lf %d %d %d %d %d %d %d %d %d %d",
+                             jsvals.quality,
+							 jsvals.smoothing,
+							 jsvals.optimize,
+							 jsvals.progressive,
+							 jsvals.subsmp,
+							 jsvals.baseline,
+							 jsvals.restart,
+							 jsvals.dct,
+							 jsvals.preview,
+							 jsvals.save_exif,
+							 jsvals.save_thumbnail,
+							 jsvals.save_xmp);
+  parasite = gimp_parasite_new (JPEG_DEFAULTS_PARASITE,
+                                GIMP_PARASITE_PERSISTENT,
+                                strlen (def_str), def_str);
+
+  gimp_parasite_attach (parasite);
+
+  gimp_parasite_free (parasite);
+  g_free (def_str);
+}
+
+static void
+load_gui_defaults (JpegSaveGui *pg)
+{
+GtkAdjustment *restart_markers;
+  if (! load_defaults ())
+    {
+      g_message (_("Could not load JPEG defaults"));
+      return;
+    }
+
+#define SET_ACTIVE_BTTN(field) \
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pg->field), jsvals.field)
+
+  SET_ACTIVE_BTTN (optimize);
+  SET_ACTIVE_BTTN (progressive);
+  SET_ACTIVE_BTTN (baseline);
+  SET_ACTIVE_BTTN(preview);
+#ifdef HAVE_EXIF
+  SET_ACTIVE_BTTN(save_exif);
+  SET_ACTIVE_BTTN(save_thumbnail);
+#endif
+  SET_ACTIVE_BTTN(save_xmp);
+
+#undef SET_ACTIVE_BTTN
+
+//spin button stuff
+  g_signal_handler_block (pg->use_restart_markers, pg->handler_id_restart);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pg->use_restart_markers), jsvals.restart);
+  restart_markers = (GtkAdjustment *) pg->scale_data;
+  gtk_adjustment_set_value (restart_markers, jsvals.restart);
+  g_signal_handler_unblock (pg->use_restart_markers, pg->handler_id_restart);
+
+
+  gtk_adjustment_set_value (GTK_ADJUSTMENT (pg->quality),
+                            jsvals.quality);
+  gtk_adjustment_set_value (GTK_ADJUSTMENT (pg->smoothing),
+                            jsvals.smoothing);
+
+  gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (pg->subsmp), jsvals.subsmp);
+  gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (pg->dct), jsvals.dct);
+
+}
+
+static void
 save_restart_update (GtkAdjustment *adjustment,
                      GtkWidget     *toggle)
 {
