Index: gtk/gtkpagesetup.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpagesetup.c,v
retrieving revision 1.3
diff -p -u -B -r1.3 gtkpagesetup.c
--- gtk/gtkpagesetup.c	23 Apr 2006 05:48:04 -0000	1.3
+++ gtk/gtkpagesetup.c	4 Dec 2006 15:04:42 -0000
@@ -22,8 +22,11 @@
 
 #include "gtkpagesetup.h"
 #include "gtkprintutils.h"
+#include "gtkintl.h"
+#include "gtktypebuiltins.h"
 #include "gtkalias.h"
 
+#define KEYFILE_GROUP_NAME "Page Setup"
 
 typedef struct _GtkPageSetupClass GtkPageSetupClass;
 
@@ -455,6 +458,265 @@ gtk_page_setup_get_page_height (GtkPageS
   return _gtk_print_convert_from_mm (height, unit);
 }
 
+
+/**
+ * gtk_page_setup_new_from_file:
+ * @file_name: the filename to read the page_setup from
+ * @group_name: the name of the group in the key_file to read, or %NULL
+ * to use the first group
+ * @error:
+ * 
+ * Reads the page setup from the group @group_name in the key file
+ * @file_name. Returns a new #GtkPageSetup object with the restored
+ * page setup, or %NULL if an error occurred.
+ *
+ * Return value: the restored #GtkPageSetup
+ * 
+ * Since: 2.12
+ */
+GtkPageSetup *
+gtk_page_setup_new_from_file (const gchar *file_name,
+			      GError     **error)
+{
+  GtkPageSetup *page_setup;
+  GKeyFile *key_file;
+  GError *err = NULL;
+
+  g_return_val_if_fail (file_name != NULL, NULL);
+
+  key_file = g_key_file_new ();
+  if (!g_key_file_load_from_file (key_file, file_name, 0, &err))
+    {
+      g_key_file_free (key_file);
+      g_propagate_error (error, err);
+      return NULL;
+    }
+
+  page_setup = gtk_page_setup_new_from_key_file (key_file, NULL, error);
+  g_key_file_free (key_file);
+
+  return page_setup;
+}
+
+/* something like this should really be in gobject! */
+guint
+string_to_enum (GType type,
+                const char *enum_string)
+{
+  GEnumClass *enum_class;
+  const GEnumValue *value;
+  guint retval = 0;
+
+  g_return_val_if_fail (enum_string != NULL, 0);
+
+  enum_class = g_type_class_ref (type);
+  value = g_enum_get_value_by_nick (enum_class, enum_string);
+  if (value)
+    retval = value->value;
+
+  g_type_class_unref (enum_class);
+
+  return retval;
+}
+
+#define ERROR_QUARK (g_quark_from_static_string (I_("gtk-page-setup-error-quark")))
+
+/**
+ * gtk_page_setup_new_from_key_file:
+ * @key_file: the #GKeyFile to retrieve the page_setup from
+ * @group_name: the name of the group in the key_file to read, or %NULL
+ * to use the default
+ * @error:
+ * 
+ * Reads the page setup from the group @group_name in the key file
+ * @key_file. Returns a new #GtkPageSetup object with the restored
+ * page setup, or %NULL if an error occurred.
+ *
+ * Return value: the restored #GtkPageSetup
+ * 
+ * Since: 2.12
+ */
+GtkPageSetup *
+gtk_page_setup_new_from_key_file (GKeyFile *key_file,
+			          const gchar *group_name,
+				  GError  **error)
+{
+  GtkPageSetup *page_setup = NULL;
+  GtkPaperSize *paper_size;
+  gdouble top, bottom, left, right;
+  char *orientation = NULL, *freeme = NULL;
+  gboolean retval = TRUE;
+  GError *err = NULL;
+
+  g_return_val_if_fail (key_file != NULL, NULL);
+
+  if (!group_name)
+    group_name = KEYFILE_GROUP_NAME;
+
+  if (!g_key_file_has_group (key_file, group_name))
+    {
+      g_set_error (error,
+		   ERROR_QUARK,
+		   0,
+		   _("Not a valid gtk page setup file"));
+      retval = FALSE;
+      goto out;
+    }
+
+#define GET_DOUBLE(kf, group, name, v) \
+v = g_key_file_get_double (kf, group, name, &err); \
+if (err != NULL) {\
+  g_propagate_error (error, err);\
+  retval = FALSE;\
+  goto out;\
+}
+
+  GET_DOUBLE (key_file, group_name, "MarginTop", top);
+  GET_DOUBLE (key_file, group_name, "MarginBottom", bottom);
+  GET_DOUBLE (key_file, group_name, "MarginLeft", left);
+  GET_DOUBLE (key_file, group_name, "MarginRight", right);
+
+#undef GET_DOUBLE
+
+  paper_size = gtk_paper_size_new_from_key_file (key_file, group_name, &err);
+  if (!paper_size)
+    {
+      g_propagate_error (error, err);
+      goto out;
+    }
+
+  page_setup = gtk_page_setup_new ();
+  gtk_page_setup_set_paper_size (page_setup, paper_size);
+  gtk_paper_size_free (paper_size);
+
+  gtk_page_setup_set_top_margin (page_setup, top, GTK_UNIT_MM);
+  gtk_page_setup_set_bottom_margin (page_setup, bottom, GTK_UNIT_MM);
+  gtk_page_setup_set_left_margin (page_setup, left, GTK_UNIT_MM);
+  gtk_page_setup_set_right_margin (page_setup, right, GTK_UNIT_MM);
+
+  orientation = g_key_file_get_string (key_file, group_name,
+				       "Orientation", NULL);
+  if (orientation)
+    {
+      gtk_page_setup_set_orientation (page_setup,
+				      string_to_enum (GTK_TYPE_PAGE_ORIENTATION,
+						      orientation));
+      g_free (orientation);
+    }
+
+out:
+  g_free (freeme);
+
+  return page_setup;
+}
+
+/**
+ * gtk_page_setup_to_file:
+ * @page_setup: a #GtkPageSetup
+ * @file_name: the file to save to
+ * @error:
+ * 
+ * This function saves the print page_setup from @page_setup to @file_name.
+ * 
+ * Return value: %TRUE on success
+ *
+ * Since: 2.12
+ */
+gboolean
+gtk_page_setup_to_file (GtkPageSetup *page_setup,
+		        const char   *file_name,
+			GError      **error)
+{
+  GKeyFile *key_file;
+  gboolean retval = FALSE;
+  char *data = NULL;
+  gsize len;
+
+  g_return_val_if_fail (GTK_IS_PAGE_SETUP (page_setup), FALSE);
+  g_return_val_if_fail (file_name != NULL, FALSE);
+
+  key_file = g_key_file_new ();
+  gtk_page_setup_to_key_file (page_setup, key_file, NULL);
+
+  data = g_key_file_to_data (key_file, &len, error);
+  if (!data)
+    goto out;
+
+  retval = g_file_set_contents (file_name, data, len, error);
+
+out:
+  g_key_file_free (key_file);
+  g_free (data);
+
+  return retval;
+}
+
+/* something like this should really be in gobject! */
+static char *
+enum_to_string (GType type,
+                guint enum_value)
+{
+  GEnumClass *enum_class;
+  GEnumValue *value;
+  char *retval = NULL;
+
+  enum_class = g_type_class_ref (type);
+
+  value = g_enum_get_value (enum_class, enum_value);
+  if (value)
+    retval = g_strdup (value->value_nick);
+
+  g_type_class_unref (enum_class);
+
+  return retval;
+}
+
+/**
+ * gtk_page_setup_to_key_file:
+ * @page_setup: a #GtkPageSetup
+ * @key_file: the #GKeyFile to save the print page_setup to
+ * @group_name: the group to add the settings to in @key_file, or %NULL to use the default
+ * 
+ * This function adds the print page_setup from @page_setup to @key_file.
+ * 
+ * Return value: %TRUE on success
+ *
+ * Since: 2.12
+ */
+void
+gtk_page_setup_to_key_file (GtkPageSetup *page_setup,
+			    GKeyFile     *key_file,
+			    const gchar  *group_name)
+{
+  GtkPaperSize *paper_size;
+  char *orientation;
+
+  g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
+  g_return_if_fail (key_file != NULL);
+
+  if (!group_name)
+    group_name = KEYFILE_GROUP_NAME;
+
+  paper_size = gtk_page_setup_get_paper_size (page_setup);
+  g_assert (paper_size != NULL);
+
+  gtk_paper_size_to_key_file (paper_size, key_file, group_name);
+
+  g_key_file_set_double (key_file, group_name,
+			 "MarginTop", gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
+  g_key_file_set_double (key_file, group_name,
+			 "MarginBottom", gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
+  g_key_file_set_double (key_file, group_name,
+			 "MarginLeft", gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
+  g_key_file_set_double (key_file, group_name,
+			 "MarginRight", gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
+
+  orientation = enum_to_string (GTK_TYPE_PAGE_ORIENTATION,
+				gtk_page_setup_get_orientation (page_setup));
+  g_key_file_set_string (key_file, group_name,
+			 "Orientation", orientation);
+  g_free (orientation);
+}
 
 #define __GTK_PAGE_SETUP_C__
 #include "gtkaliasdef.c"
Index: gtk/gtkpagesetup.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpagesetup.h,v
retrieving revision 1.3
diff -p -u -B -r1.3 gtkpagesetup.h
--- gtk/gtkpagesetup.h	23 Apr 2006 05:48:04 -0000	1.3
+++ gtk/gtkpagesetup.h	4 Dec 2006 15:04:42 -0000
@@ -79,6 +79,18 @@ gdouble            gtk_page_setup_get_pa
 gdouble            gtk_page_setup_get_page_height   (GtkPageSetup       *setup,
 						     GtkUnit             unit);
 
+/* Saving and restoring page setup */
+GtkPageSetup	  *gtk_page_setup_new_from_file	    (const gchar         *file_name,
+						     GError              **error);
+gboolean	   gtk_page_setup_to_file	    (GtkPageSetup        *setup,
+						     const char          *file_name,
+						     GError             **error);
+GtkPageSetup	  *gtk_page_setup_new_from_key_file (GKeyFile            *key_file,
+						     const gchar         *group_name,
+						     GError             **error);
+void		   gtk_page_setup_to_key_file	    (GtkPageSetup        *setup,
+						     GKeyFile            *key_file,
+						     const gchar         *group_name);
 
 G_END_DECLS
 
Index: gtk/gtkprintsettings.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkprintsettings.c,v
retrieving revision 1.10
diff -p -u -B -r1.10 gtkprintsettings.c
--- gtk/gtkprintsettings.c	3 Oct 2006 18:01:33 -0000	1.10
+++ gtk/gtkprintsettings.c	4 Dec 2006 15:04:43 -0000
@@ -45,6 +45,8 @@ struct _GtkPrintSettingsClass
   GObjectClass parent_class;
 };
 
+#define KEYFILE_GROUP_NAME "Print Settings"
+
 G_DEFINE_TYPE (GtkPrintSettings, gtk_print_settings, G_TYPE_OBJECT)
 
 static void
@@ -1499,7 +1501,192 @@ gtk_print_settings_set_output_bin (GtkPr
 {
   gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_BIN, output_bin);
 }
+
+/**
+ * gtk_print_settings_new_from_file:
+ * @file_name: the filename to read the settings from
+ * @error:
+ * 
+ * Reads the print settings from @filename. Returns a new #GtkPrintSettings
+ * object with the restored settings, or %NULL if an error occurred.
+ *
+ * Return value: the restored #GtkPrintSettings
+ * 
+ * Since: 2.12
+ */
+GtkPrintSettings *
+gtk_print_settings_new_from_file (const gchar *file_name,
+			         GError     **error)
+{
+  GtkPrintSettings *settings;
+  GKeyFile *key_file;
+
+  g_return_val_if_fail (file_name != NULL, NULL);
+
+  key_file = g_key_file_new ();
+  if (!g_key_file_load_from_file (key_file, file_name, 0, error))
+    {
+      g_key_file_free (key_file);
+      return NULL;
+    }
+
+  settings = gtk_print_settings_new_from_key_file (key_file, NULL, error);
+  g_key_file_free (key_file);
+
+  return settings;
+}
+
+/**
+ * gtk_print_settings_new_from_key_file:
+ * @key_file: the #GKeyFile to retrieve the settings from
+ * @error:
+ * 
+ * Reads the print settings from @key_file. Returns a new #GtkPrintSettings
+ * object with the restored settings, or %NULL if an error occurred.
+ *
+ * Return value: the restored #GtkPrintSettings
+ * 
+ * Since: 2.12
+ */
+GtkPrintSettings *
+gtk_print_settings_new_from_key_file (GKeyFile *key_file,
+				      const gchar *group_name,
+				      GError  **error)
+{
+  GtkPrintSettings *settings;
+  gchar **keys;
+  gsize n_keys, i;
+  GError *err = NULL;
+
+  g_return_val_if_fail (key_file != NULL, NULL);
+
+  if (!group_name)
+    group_name = KEYFILE_GROUP_NAME;
+
+  keys = g_key_file_get_keys (key_file,
+			      group_name,
+			      &n_keys,
+			      &err);
+  if (err != NULL)
+    {
+      g_propagate_error (error, err);
+      return NULL;
+    }
    
+  settings = gtk_print_settings_new ();
+
+  for (i = 0 ; i < n_keys; ++i)
+    {
+      gchar *value;
+
+      value = g_key_file_get_string (key_file,
+				     KEYFILE_GROUP_NAME,
+				     keys[i],
+				     NULL);
+      if (!value)
+        continue;
+
+      gtk_print_settings_set (settings, keys[i], value);
+      g_free (value);
+    }
+
+  g_strfreev (keys);
+
+  return settings;
+}
+
+/**
+ * gtk_print_settings_to_file:
+ * @settings: a #GtkPrintSettings
+ * @file_name: the file to save to
+ * @error:
+ * 
+ * This function saves the print settings from @settings to @file_name.
+ * 
+ * Return value: %TRUE on success
+ *
+ * Since: 2.12
+ */
+gboolean
+gtk_print_settings_to_file (GtkPrintSettings     *settings,
+			    const char           *file_name,
+			    GError              **error)
+{
+  GKeyFile *key_file;
+  gboolean retval = FALSE;
+  char *data = NULL;
+  gsize len;
+  GError *err = NULL;
+
+  g_return_val_if_fail (GTK_IS_PRINT_SETTINGS (settings), FALSE);
+  g_return_val_if_fail (file_name != NULL, FALSE);
+
+  key_file = g_key_file_new ();
+  gtk_print_settings_to_key_file (settings, key_file, NULL);
+
+  data = g_key_file_to_data (key_file, &len, &err);
+  if (!data)
+    goto out;
+
+  retval = g_file_set_contents (file_name, data, len, &err);
+
+out:
+  if (err != NULL)
+    g_propagate_error (error, err);
+
+  g_key_file_free (key_file);
+  g_free (data);
+
+  return retval;
+}
+
+typedef struct {
+  GKeyFile *key_file;
+  const gchar *group_name;
+} SettingsData;
+
+static void
+add_value_to_key_file (const gchar *key,
+		       const gchar *value,
+		       SettingsData *data)
+{
+  g_key_file_set_string (data->key_file,
+			 data->group_name,
+			 key,
+			 value);
+}
+
+/**
+ * gtk_print_settings_to_key_file:
+ * @settings: a #GtkPrintSettings
+ * @key_file: the #GKeyFile to save the print settings to
+ * @group_name: the group to add the settings to in @key_file, or %NULL to use the default
+ *
+ * This function adds the print settings from @settings to @key_file.
+ * 
+ * Since: 2.12
+ */
+void
+gtk_print_settings_to_key_file (GtkPrintSettings  *settings,
+			        GKeyFile          *key_file,
+				const gchar       *group_name)
+{
+  SettingsData data;
+
+  g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
+  g_return_if_fail (key_file != NULL);
+
+  if (!group_name)
+    group_name = KEYFILE_GROUP_NAME;
+
+  data.key_file = key_file;
+  data.group_name = group_name;
+
+  gtk_print_settings_foreach (settings,
+			      (GtkPrintSettingsFunc) add_value_to_key_file,
+			      &data);
+}
+
 
 #define __GTK_PRINT_SETTINGS_C__
 #include "gtkaliasdef.c"
Index: gtk/gtkprintsettings.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkprintsettings.h,v
retrieving revision 1.7
diff -p -u -B -r1.7 gtkprintsettings.h
--- gtk/gtkprintsettings.h	20 Jun 2006 17:36:42 -0000	1.7
+++ gtk/gtkprintsettings.h	4 Dec 2006 15:04:43 -0000
@@ -46,6 +46,18 @@ GType             gtk_print_settings_get
 GtkPrintSettings *gtk_print_settings_new      (void);
 
 GtkPrintSettings *gtk_print_settings_copy                    (GtkPrintSettings     *other);
+
+GtkPrintSettings *gtk_print_settings_new_from_file           (const gchar          *file_name,
+							      GError              **error);
+gboolean          gtk_print_settings_to_file                 (GtkPrintSettings     *settings,
+							      const gchar          *file_name,
+							      GError              **error);
+GtkPrintSettings *gtk_print_settings_new_from_key_file       (GKeyFile             *key_file,
+							      const gchar          *group_name,
+							      GError              **error);
+void              gtk_print_settings_to_key_file             (GtkPrintSettings     *settings,
+							      GKeyFile             *key_file,
+							      const gchar          *group_name);
 gboolean          gtk_print_settings_has_key                 (GtkPrintSettings     *settings,
 							      const gchar          *key);
 G_CONST_RETURN gchar *gtk_print_settings_get                (GtkPrintSettings     *settings,
Index: gtk/gtkpapersize.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpapersize.c,v
retrieving revision 1.6
diff -p -u -B -r1.6 gtkpapersize.c
--- gtk/gtkpapersize.c	10 Jul 2006 16:36:10 -0000	1.6
+++ gtk/gtkpapersize.c	4 Dec 2006 15:04:43 -0000
@@ -51,7 +51,7 @@ gtk_paper_size_get_type (void)
 {
   static GType our_type = 0;
   
-  if (our_type == 0)
+  if (G_UNLIKELY (our_type == 0))
     our_type = g_boxed_type_register_static ("GtkPaperSize",
 					     (GBoxedCopyFunc)gtk_paper_size_copy,
 					     (GBoxedFreeFunc)gtk_paper_size_free);
@@ -730,6 +730,120 @@ gtk_paper_size_get_default_right_margin 
 
   margin = _gtk_print_convert_to_mm (0.25, GTK_UNIT_INCH);
   return _gtk_print_convert_from_mm (margin, unit);
+}
+
+#define ERROR_QUARK (g_quark_from_static_string (I_("gtk-paper-size-error-quark")))
+
+GtkPaperSize *
+gtk_paper_size_new_from_key_file (GKeyFile    *key_file,
+				  const gchar *group_name,
+				  GError     **error)
+{
+  GtkPaperSize *paper_size = NULL;
+  char *name = NULL, *ppd_name = NULL, *display_name = NULL, *freeme = NULL;
+  gdouble width, height;
+  gboolean retval = TRUE;
+  GError *err = NULL;
+
+  g_return_val_if_fail (key_file != NULL, NULL);
+
+  if (!group_name)
+    group_name = freeme = g_key_file_get_start_group (key_file);
+  if (!group_name ||
+      !g_key_file_has_group (key_file, group_name))
+    {
+      g_set_error (error,
+		   ERROR_QUARK,
+		   0,
+		   _("Not a valid epiphany page setup file"));
+      retval = FALSE;
+      goto out;
+    }
+
+#define GET_DOUBLE(kf, group, name, v) \
+v = g_key_file_get_double (kf, group, name, &err); \
+if (err != NULL) {\
+  g_propagate_error (error, err);\
+  retval = FALSE;\
+  goto out;\
+}
+
+  GET_DOUBLE (key_file, group_name, "Width", width);
+  GET_DOUBLE (key_file, group_name, "Height", height);
+
+#undef GET_DOUBLE
+
+  name = g_key_file_get_string (key_file, group_name,
+				"Name", NULL);
+  ppd_name = g_key_file_get_string (key_file, group_name,
+				    "PPDName", NULL);
+  display_name = g_key_file_get_string (key_file, group_name,
+					"DisplayName", NULL);
+  /* Fallback for old ~/.gtk-custom-paper entries */
+  if (!display_name)
+    display_name = g_strdup (name);
+
+  if (ppd_name != NULL)
+    {
+      paper_size = gtk_paper_size_new_from_ppd (ppd_name, display_name,
+					        width, height);
+    }
+  else if (name != NULL)
+    {
+      paper_size = gtk_paper_size_new_custom (name, display_name,
+					      width, height, GTK_UNIT_MM);
+    }
+  else
+    {
+      g_set_error (error,
+		   ERROR_QUARK,
+		   0,
+		   "Not a valid epiphany page setup file");
+      retval = FALSE;
+      goto out;
+    }
+  g_assert (paper_size != NULL);
+
+out:
+  g_free (ppd_name);
+  g_free (name);
+  g_free (display_name);
+  g_free (freeme);
+
+  return paper_size;
+}
+
+void
+gtk_paper_size_to_key_file (GtkPaperSize *paper_size,
+			    GKeyFile     *key_file,
+			    const gchar  *group_name)
+{
+  const char *name, *ppd_name, *display_name;
+
+  g_return_if_fail (paper_size != NULL);
+  g_return_if_fail (key_file != NULL);
+
+  name = gtk_paper_size_get_name (paper_size);
+  display_name = gtk_paper_size_get_display_name (paper_size);
+  ppd_name = gtk_paper_size_get_ppd_name (paper_size);
+
+  if (ppd_name != NULL) {
+    g_key_file_set_string (key_file, group_name,
+			   "PPDName", ppd_name);
+  } else {
+    g_key_file_set_string (key_file, group_name,
+			   "Name", name);
+  }
+
+  if (display_name) {
+    g_key_file_set_string (key_file, group_name,
+			   "DisplayName", display_name);
+  }
+
+  g_key_file_set_double (key_file, group_name,
+			 "Width", gtk_paper_size_get_width (paper_size, GTK_UNIT_MM));
+  g_key_file_set_double (key_file, group_name,
+			 "Height", gtk_paper_size_get_height (paper_size, GTK_UNIT_MM));
 }
 
 
Index: gtk/gtkpapersize.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpapersize.h,v
retrieving revision 1.3
diff -p -u -B -r1.3 gtkpapersize.h
--- gtk/gtkpapersize.h	23 Apr 2006 06:26:10 -0000	1.3
+++ gtk/gtkpapersize.h	4 Dec 2006 15:04:43 -0000
@@ -83,6 +83,13 @@ gdouble gtk_paper_size_get_default_right
 
 G_CONST_RETURN gchar *gtk_paper_size_get_default (void);
 
+GtkPaperSize *gtk_paper_size_new_from_key_file (GKeyFile    *key_file,
+					        const gchar *group_name,
+					        GError     **error);
+void     gtk_paper_size_to_key_file            (GtkPaperSize *size,
+					        GKeyFile     *key_file,
+					        const gchar  *group_name);
+
 G_END_DECLS
 
 #endif /* __GTK_PAPER_SIZE_H__ */
Index: gtk/gtkpagesetupunixdialog.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpagesetupunixdialog.c,v
retrieving revision 1.17
diff -p -u -B -r1.17 gtkpagesetupunixdialog.c
--- gtk/gtkpagesetupunixdialog.c	3 Oct 2006 15:54:52 -0000	1.17
+++ gtk/gtkpagesetupunixdialog.c	4 Dec 2006 15:04:44 -0000
@@ -203,44 +197,13 @@ load_custom_papers (GtkListStore *store)
   groups = g_key_file_get_groups (keyfile, &n_groups);
   for (i = 0; i < n_groups; ++i)
     {
-      GError *error = NULL;
-      gdouble w, h, top, bottom, left, right;
-      GtkPaperSize *paper_size;
       GtkPageSetup *page_setup;
-      gchar *name;
       GtkTreeIter iter;
 
-      name = g_key_file_get_value (keyfile, groups[i], "Name", NULL);
-      if (!name)
+      page_setup = gtk_page_setup_new_from_key_file (keyfile, groups[i], NULL);
+      if (!page_setup)
         continue;
 
-#define GET_DOUBLE(kf, name, v) \
-      v = g_key_file_get_double (kf, groups[i], name, &error); \
-      if (error != NULL) \
-        {\
-          g_error_free (error);\
-          continue;\
-        }
-
-      GET_DOUBLE (keyfile, "Width", w);
-      GET_DOUBLE (keyfile, "Height", h);
-      GET_DOUBLE (keyfile, "MarginTop", top);
-      GET_DOUBLE (keyfile, "MarginBottom", bottom);
-      GET_DOUBLE (keyfile, "MarginLeft", left);
-      GET_DOUBLE (keyfile, "MarginRight", right);
-
-#undef GET_DOUBLE
-
-      page_setup = gtk_page_setup_new ();
-      paper_size = gtk_paper_size_new_custom (name, name, w, h, GTK_UNIT_MM);
-      gtk_page_setup_set_paper_size (page_setup, paper_size);
-      gtk_paper_size_free (paper_size);
-
-      gtk_page_setup_set_top_margin (page_setup, top, GTK_UNIT_MM);
-      gtk_page_setup_set_bottom_margin (page_setup, bottom, GTK_UNIT_MM);
-      gtk_page_setup_set_left_margin (page_setup, left, GTK_UNIT_MM);
-      gtk_page_setup_set_right_margin (page_setup, right, GTK_UNIT_MM);
-
       gtk_list_store_append (store, &iter);
       gtk_list_store_set (store, &iter,
 			  0, page_setup, 
@@ -245,9 +208,7 @@ load_custom_papers (GtkListStore *store)
       gtk_list_store_set (store, &iter,
 			  0, page_setup, 
 			  -1);
-
       g_object_unref (page_setup);
-      g_free (name);
     }
  
   g_strfreev (groups);
@@ -270,7 +231,6 @@ save_custom_papers (GtkListStore *store)
     {
       do
 	{
-	  GtkPaperSize *paper_size;
 	  GtkPageSetup *page_setup;
 	  gchar group[32];
 
@@ -278,21 +238,7 @@ save_custom_papers (GtkListStore *store)
 
 	  gtk_tree_model_get (model, &iter, 0, &page_setup, -1);
 
-	  paper_size = gtk_page_setup_get_paper_size (page_setup);
-	  g_key_file_set_string (keyfile, group, "Name", gtk_paper_size_get_name (paper_size));
-
-	  g_key_file_set_double (keyfile, group, "Width",
-				 gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM));
-	  g_key_file_set_double (keyfile, group, "Height",
-				 gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM));
-	  g_key_file_set_double (keyfile, group, "MarginTop",
-				 gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
-	  g_key_file_set_double (keyfile, group, "MarginBottom",
-				 gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
-	  g_key_file_set_double (keyfile, group, "MarginLeft",
-				 gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
-	  g_key_file_set_double (keyfile, group, "MarginRight",
-				 gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
+	  gtk_page_setup_to_key_file (page_setup, keyfile, group);
 	  
 	  ++i;
 	} while (gtk_tree_model_iter_next (model, &iter));
@@ -489,6 +434,7 @@ printer_status_cb (GtkPrintBackend      
   gtk_list_store_set (priv->printer_list, iter,
                       PRINTER_LIST_COL_NAME, str,
                       -1);
+  g_free (str);
 }
 
 static void
Index: gtk/gtk.symbols
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtk.symbols,v
retrieving revision 1.134
diff -p -u -B -r1.134 gtk.symbols
--- gtk/gtk.symbols	16 Nov 2006 12:56:29 -0000	1.134
+++ gtk/gtk.symbols	4 Dec 2006 15:04:46 -0000
@@ -2506,6 +2512,10 @@ gtk_preview_uninit
 #if IN_FILE(__GTK_PAGE_SETUP_C__)
 gtk_page_setup_get_type G_GNUC_CONST
 gtk_page_setup_new
+gtk_page_setup_new_from_file
+gtk_page_setup_new_from_key_file
+gtk_page_setup_to_file
+gtk_page_setup_to_key_file
 gtk_page_setup_copy
 gtk_page_setup_get_orientation
 gtk_page_setup_set_orientation
@@ -2546,6 +2556,8 @@ gtk_paper_size_get_type G_GNUC_CONST
 gtk_paper_size_new
 gtk_paper_size_new_from_ppd
 gtk_paper_size_new_custom
+gtk_paper_size_new_from_key_file
+gtk_paper_size_to_key_file
 gtk_paper_size_copy
 gtk_paper_size_free
 gtk_paper_size_is_equal
@@ -2762,6 +2775,10 @@ gtk_print_run_page_setup_dialog_async
 #if IN_FILE(__GTK_PRINT_SETTINGS_C__)
 gtk_print_settings_get_type G_GNUC_CONST
 gtk_print_settings_new
+gtk_print_settings_new_from_file
+gtk_print_settings_new_from_key_file
+gtk_print_settings_to_file
+gtk_print_settings_to_key_file
 gtk_print_settings_copy
 gtk_print_settings_has_key
 gtk_print_settings_get
Index: tests/print-editor.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/print-editor.c,v
retrieving revision 1.12
diff -p -u -B -r1.12 print-editor.c
--- tests/print-editor.c	16 Jun 2006 16:39:09 -0000	1.12
+++ tests/print-editor.c	4 Dec 2006 15:04:46 -0000
@@ -370,9 +370,6 @@ do_page_setup (GtkAction *action)
 {
   GtkPageSetup *new_page_setup;
 
-  if (settings == NULL)
-    settings = gtk_print_settings_new ();
-  
   new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (main_window),
 						    page_setup, settings);
 
@@ -826,9 +823,14 @@ create_window (void)
   GtkWidget *sw;
   GtkActionGroup *actions;
   GError *error;
+  GtkWindowGroup *group;
   
   main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
+  group = gtk_window_group_new ();
+  gtk_window_group_add_window (group, GTK_WINDOW (main_window));
+  g_object_unref (group);
+
   gtk_window_set_default_size (GTK_WINDOW (main_window),
 			       400, 600);
   
@@ -925,14 +927,42 @@ create_window (void)
 int
 main (int argc, char **argv)
 {
+  GError *error = NULL;
+
   g_set_application_name ("Print editor");
   gtk_init (&argc, &argv);
 
+  settings = gtk_print_settings_new_from_file ("print-settings.ini", &error);
+  if (error) {
+    g_print ("Failed to load print settings: %s\n", error->message);
+    g_clear_error (&error);
+
+    settings = gtk_print_settings_new ();
+  }
+  g_assert (settings != NULL);
+
+  page_setup = gtk_page_setup_new_from_file ("page-setup.ini", &error);
+  if (error) {
+    g_print ("Failed to load page setup: %s\n", error->message);
+    g_clear_error (&error);
+  }
+
   create_window ();
 
   if (argc == 2)
     load_file (argv[1]);
   
   gtk_main ();
+
+  if (!gtk_print_settings_to_file (settings, "print-settings.ini", &error)) {
+    g_print ("Failed to save print settings: %s\n", error->message);
+    g_clear_error (&error);
+  }
+  if (page_setup &&
+      !gtk_page_setup_to_file (page_setup, "page-setup.ini", &error)) {
+    g_print ("Failed to save page setup: %s\n", error->message);
+    g_clear_error (&error);
+  }
+
   return 0;
 }
