diff options
author | Mathias Hasselmann <hasselmm@src.gnome.org> | 2007-12-14 09:02:54 +0000 |
---|---|---|
committer | Mathias Hasselmann <hasselmm@src.gnome.org> | 2007-12-14 09:02:54 +0000 |
commit | ea8074a4077ac7bf90f3873160da35bd491e8079 (patch) | |
tree | c8f996191b97e96ed1304848928507b4a13e7cf0 /gtk/gtkprintsettings.c | |
parent | da057b56750a588f0216d6dc69b7a898a12480f9 (diff) | |
download | gtk+-ea8074a4077ac7bf90f3873160da35bd491e8079.tar.gz |
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.
svn path=/trunk/; revision=19176
Diffstat (limited to 'gtk/gtkprintsettings.c')
-rw-r--r-- | gtk/gtkprintsettings.c | 109 |
1 files changed, 83 insertions, 26 deletions
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; } |