summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--gtk/gtk.symbols4
-rw-r--r--gtk/gtkpagesetup.c129
-rw-r--r--gtk/gtkpagesetup.h7
-rw-r--r--gtk/gtkprintsettings.c109
-rw-r--r--gtk/gtkprintsettings.h7
6 files changed, 204 insertions, 63 deletions
diff --git a/ChangeLog b/ChangeLog
index 03de07a09a..d53bfb14d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-12-14 Mathias Hasselmann <mathias@openismus.com>
+
+ Extract loading of GtkPageSetup and GtkPrintSettings from their
+ *_new_*() functions and move that code into separate
+ *_load_*() functions (#475565).
+
+ * gtk/gtk.symbols, gtk/gtkpagesetup.c, gtk/gtkpagesetup.h:
+ Extract gtk_page_setup_load_file, gtk_page_setup_load_key_file,
+ gtk_print_settings_load_file and gtk_print_settings_load_key_file.
+ Change the matching *_new_*() functions to use those functions.
+
2007-12-14 Matthias Clasen <mclasen@redhat.com>
* gtk/gtk.symbols:
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index c928acfdb0..917c6e8ea9 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -2580,6 +2580,8 @@ 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_load_file
+gtk_page_setup_load_key_file
gtk_page_setup_to_file
gtk_page_setup_to_key_file
gtk_page_setup_copy
@@ -2847,6 +2849,8 @@ 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_load_file
+gtk_print_settings_load_key_file
gtk_print_settings_to_file
gtk_print_settings_to_key_file
gtk_print_settings_copy
diff --git a/gtk/gtkpagesetup.c b/gtk/gtkpagesetup.c
index b7a0aa3f9a..ab6a224dd3 100644
--- a/gtk/gtkpagesetup.c
+++ b/gtk/gtkpagesetup.c
@@ -471,6 +471,40 @@ gtk_page_setup_get_page_height (GtkPageSetup *setup,
return _gtk_print_convert_from_mm (height, unit);
}
+/**
+ * gtk_page_setup_load_file:
+ * @setup: a #GtkPageSetup
+ * @file_name: the filename to read the page setup from
+ * @error: return location for an error, or %NULL
+ *
+ * Reads the page setup from the file @file_name.
+ * See gtk_page_setup_load_file().
+ *
+ * Return value: %TRUE on success
+ *
+ * Since: 2.14
+ */
+gboolean
+gtk_page_setup_load_file (GtkPageSetup *setup,
+ const gchar *file_name,
+ GError **error)
+{
+ gboolean retval = FALSE;
+ GKeyFile *key_file;
+
+ g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), FALSE);
+ g_return_val_if_fail (file_name != NULL, FALSE);
+
+ key_file = g_key_file_new ();
+
+ if (g_key_file_load_from_file (key_file, file_name, 0, error) &&
+ gtk_page_setup_load_key_file (setup, key_file, NULL, error))
+ retval = TRUE;
+
+ g_key_file_free (key_file);
+
+ return retval;
+}
/**
* gtk_page_setup_new_from_file:
@@ -489,24 +523,15 @@ 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);
+ GtkPageSetup *setup = gtk_page_setup_new ();
- key_file = g_key_file_new ();
- if (!g_key_file_load_from_file (key_file, file_name, 0, &err))
+ if (!gtk_page_setup_load_file (setup, file_name, error))
{
- g_key_file_free (key_file);
- g_propagate_error (error, err);
- return NULL;
+ g_object_unref (setup);
+ setup = NULL;
}
- page_setup = gtk_page_setup_new_from_key_file (key_file, NULL, error);
- g_key_file_free (key_file);
-
- return page_setup;
+ return setup;
}
/* something like this should really be in gobject! */
@@ -531,33 +556,34 @@ string_to_enum (GType type,
}
/**
- * gtk_page_setup_new_from_key_file:
+ * gtk_page_setup_load_key_file:
+ * @setup: a #GtkPageSetup
* @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 name "Page Setup"
* @error: return location for an error, or %NULL
*
* 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
+ * @key_file.
*
- * Since: 2.12
+ * Return value: %TRUE on success
+ *
+ * Since: 2.14
*/
-GtkPageSetup *
-gtk_page_setup_new_from_key_file (GKeyFile *key_file,
- const gchar *group_name,
- GError **error)
+gboolean
+gtk_page_setup_load_key_file (GtkPageSetup *setup,
+ 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;
+ gboolean retval = FALSE;
GError *err = NULL;
- g_return_val_if_fail (key_file != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), FALSE);
+ g_return_val_if_fail (key_file != NULL, FALSE);
if (!group_name)
group_name = KEYFILE_GROUP_NAME;
@@ -568,7 +594,6 @@ gtk_page_setup_new_from_key_file (GKeyFile *key_file,
GTK_PRINT_ERROR,
GTK_PRINT_ERROR_INVALID_FILE,
_("Not a valid page setup file"));
- retval = FALSE;
goto out;
}
@@ -577,7 +602,6 @@ gtk_page_setup_new_from_key_file (GKeyFile *key_file,
if (err != NULL) \
{ \
g_propagate_error (error, err);\
- retval = FALSE;\
goto out;\
}
@@ -595,29 +619,60 @@ gtk_page_setup_new_from_key_file (GKeyFile *key_file,
goto out;
}
- page_setup = gtk_page_setup_new ();
- gtk_page_setup_set_paper_size (page_setup, paper_size);
+ gtk_page_setup_set_paper_size (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_page_setup_set_top_margin (setup, top, GTK_UNIT_MM);
+ gtk_page_setup_set_bottom_margin (setup, bottom, GTK_UNIT_MM);
+ gtk_page_setup_set_left_margin (setup, left, GTK_UNIT_MM);
+ gtk_page_setup_set_right_margin (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,
+ gtk_page_setup_set_orientation (setup,
string_to_enum (GTK_TYPE_PAGE_ORIENTATION,
orientation));
g_free (orientation);
}
+ retval = TRUE;
+
out:
g_free (freeme);
+ return retval;
+}
+
+/**
+ * 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 name "Page Setup"
+ * @error: return location for an error, or %NULL
+ *
+ * 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 *setup = gtk_page_setup_new ();
+
+ if (!gtk_page_setup_load_key_file (setup, key_file, group_name, error))
+ {
+ g_object_unref (setup);
+ setup = NULL;
+ }
- return page_setup;
+ return setup;
}
/**
diff --git a/gtk/gtkpagesetup.h b/gtk/gtkpagesetup.h
index 6de2ef5f3f..e73908195f 100644
--- a/gtk/gtkpagesetup.h
+++ b/gtk/gtkpagesetup.h
@@ -82,12 +82,19 @@ gdouble gtk_page_setup_get_page_height (GtkPageSetup *setup,
/* Saving and restoring page setup */
GtkPageSetup *gtk_page_setup_new_from_file (const gchar *file_name,
GError **error);
+gboolean gtk_page_setup_load_file (GtkPageSetup *setup,
+ const char *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);
+gboolean gtk_page_setup_load_key_file (GtkPageSetup *setup,
+ 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);
diff --git a/gtk/gtkprintsettings.c b/gtk/gtkprintsettings.c
index 321bc7c5bb..ff14eee829 100644
--- a/gtk/gtkprintsettings.c
+++ b/gtk/gtkprintsettings.c
@@ -1503,11 +1503,46 @@ gtk_print_settings_set_output_bin (GtkPrintSettings *settings,
}
/**
+ * gtk_print_settings_load_file:
+ * @settings: a #GtkPrintSettings
+ * @file_name: the filename to read the settings from
+ * @error: return location for errors, or %NULL
+ *
+ * Reads the print settings from @file_name.
+ * See gtk_print_settings_to_file().
+ *
+ * Return value: %TRUE on success
+ *
+ * Since: 2.14
+ */
+gboolean
+gtk_print_settings_load_file (GtkPrintSettings *settings,
+ const gchar *file_name,
+ GError **error)
+{
+ gboolean retval = FALSE;
+ GKeyFile *key_file;
+
+ 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 ();
+
+ if (g_key_file_load_from_file (key_file, file_name, 0, error) &&
+ gtk_print_settings_load_key_file (settings, key_file, NULL, error))
+ retval = TRUE;
+
+ g_key_file_free (key_file);
+
+ return retval;
+}
+
+/**
* gtk_print_settings_new_from_file:
* @file_name: the filename to read the settings from
* @error: return location for errors, or %NULL
*
- * Reads the print settings from @filename. Returns a new #GtkPrintSettings
+ * Reads the print settings from @file_name. Returns a new #GtkPrintSettings
* object with the restored settings, or %NULL if an error occurred.
* See gtk_print_settings_to_file().
*
@@ -1519,49 +1554,42 @@ 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);
+ GtkPrintSettings *settings = gtk_print_settings_new ();
- key_file = g_key_file_new ();
- if (!g_key_file_load_from_file (key_file, file_name, 0, error))
+ if (!gtk_print_settings_load_file (settings, file_name, error))
{
- g_key_file_free (key_file);
- return NULL;
+ g_object_unref (settings);
+ settings = 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:
+ * gtk_print_settings_load_key_file:
+ * @settings: a #GtkPrintSettings
* @key_file: the #GKeyFile to retrieve the settings from
* @group_name: the name of the group to use
* @error: return location for errors, or %NULL
*
* Reads the print settings from the group @group_name in @key_file.
- * Returns a new #GtkPrintSettings object with the restored settings,
- * or %NULL if an error occurred.
*
- * Return value: the restored #GtkPrintSettings
+ * Return value: %TRUE on success
*
- * Since: 2.12
+ * Since: 2.14
*/
-GtkPrintSettings *
-gtk_print_settings_new_from_key_file (GKeyFile *key_file,
- const gchar *group_name,
- GError **error)
+gboolean
+gtk_print_settings_load_key_file (GtkPrintSettings *settings,
+ 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);
+ g_return_val_if_fail (GTK_IS_PRINT_SETTINGS (settings), FALSE);
+ g_return_val_if_fail (key_file != NULL, FALSE);
if (!group_name)
group_name = KEYFILE_GROUP_NAME;
@@ -1573,11 +1601,9 @@ gtk_print_settings_new_from_key_file (GKeyFile *key_file,
if (err != NULL)
{
g_propagate_error (error, err);
- return NULL;
+ return FALSE;
}
- settings = gtk_print_settings_new ();
-
for (i = 0 ; i < n_keys; ++i)
{
gchar *value;
@@ -1595,6 +1621,37 @@ gtk_print_settings_new_from_key_file (GKeyFile *key_file,
g_strfreev (keys);
+ return TRUE;
+}
+
+/**
+ * gtk_print_settings_new_from_key_file:
+ * @key_file: the #GKeyFile to retrieve the settings from
+ * @group_name: the name of the group to use
+ * @error: return location for errors, or %NULL
+ *
+ * Reads the print settings from the group @group_name in @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 = gtk_print_settings_new ();
+
+ if (!gtk_print_settings_load_key_file (settings, key_file,
+ group_name, error))
+ {
+ g_object_unref (settings);
+ settings = NULL;
+ }
+
return settings;
}
diff --git a/gtk/gtkprintsettings.h b/gtk/gtkprintsettings.h
index 0e731187c8..09ba0b466a 100644
--- a/gtk/gtkprintsettings.h
+++ b/gtk/gtkprintsettings.h
@@ -49,12 +49,19 @@ GtkPrintSettings *gtk_print_settings_copy (GtkPrintSettings
GtkPrintSettings *gtk_print_settings_new_from_file (const gchar *file_name,
GError **error);
+gboolean gtk_print_settings_load_file (GtkPrintSettings *settings,
+ 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);
+gboolean gtk_print_settings_load_key_file (GtkPrintSettings *settings,
+ 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);