From 9862306af9b5019372cbcb6693b5ae1d56297776 Mon Sep 17 00:00:00 2001 From: Srinivasa Ragavan Date: Mon, 12 Feb 2007 06:11:14 +0000 Subject: Print migration updates from Ebby Wiselyn. svn path=/trunk/; revision=33201 --- e-util/e-print.c | 183 ++++++++++++++++++------------------------------------- 1 file changed, 59 insertions(+), 124 deletions(-) (limited to 'e-util/e-print.c') diff --git a/e-util/e-print.c b/e-util/e-print.c index 33eecca14b..edec919eac 100644 --- a/e-util/e-print.c +++ b/e-util/e-print.c @@ -19,155 +19,89 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ +#include "e-print.h" + #include #include -#include -#include "e-print.h" #include #include -#define PRINTER "/apps/evolution/shell/printer" -#define SCALE "/apps/evolution/shell/scale" -#define PRINT_PAGES "/apps/evolution/shell/print_pages" -#define PAGE_RANGES "/apps/evolution/shell/page_ranges" -#define PAGE_SET "/apps/evolution/shell/page_set" -#define COLLATE "/apps/evolution/shell/collate" -#define REVERSE "/apps/evolution/shell/reverse" -#define N_COPIES "/apps/evolution/shell/n_copies" -#define LPR_COMMANDLINE "/apps/evolution/shell/lpr_commandline" -#define OUTPUT_URI "/apps/evolution/shell/output_uri" -#define OUTPUT_FILE_FORMAT "/apps/evolution/shell/output_file_format" - -/* Loads the print settings that were saved previously */ +#include +#define PRINTING "/apps/evolution/shell/printing" +static void +pack_settings (const gchar *key, const gchar *value, GSList **p_list) +{ + gchar *item; + item = g_strdup_printf ("%s=%s", key, value); + *p_list = g_slist_prepend (*p_list, item); +} +static void +unpack_settings (gchar *item, GtkPrintSettings *settings) +{ + gchar *cp, *key, *value; + cp = strchr (item, '='); + if (cp == NULL) + return; + *cp ++ = '\0'; + key = g_strstrip (item); + value = g_strstrip (cp); + gtk_print_settings_set (settings, key, value); + g_free (item); +} GtkPrintSettings * -e_print_load_config (void) +e_print_load_settings (void) { - GConfClient *gconf; + GConfClient *client; GtkPrintSettings *settings; - gchar *printer_name; - gchar *collate; - gchar *n_copies; - gchar *print_pages; - gchar *page_set; - gchar *scale; - gchar *output_uri; - gchar *output_file_format; - gchar *reverse; - gchar *page_ranges; - gchar *lpr_commandline; + GSList *list; + GError *error = NULL; + client = gconf_client_get_default (); settings = gtk_print_settings_new (); - gconf = gconf_client_get_default (); - - printer_name = gconf_client_get_string (gconf, PRINTER, NULL); - gtk_print_settings_set (settings, "printer", printer_name); - - n_copies = gconf_client_get_string (gconf, N_COPIES, NULL); - gtk_print_settings_set (settings, "n-copies",n_copies); - - collate = gconf_client_get_string (gconf, COLLATE, NULL); - gtk_print_settings_set (settings, "collate", collate); - - lpr_commandline = gconf_client_get_string (gconf, LPR_COMMANDLINE, NULL); - gtk_print_settings_set (settings, "lpr-commandline", lpr_commandline); - - print_pages = gconf_client_get_string (gconf, PRINT_PAGES, NULL); - gtk_print_settings_set (settings, "print-pages", print_pages); - - page_set = gconf_client_get_string (gconf, PAGE_SET, NULL); - gtk_print_settings_set (settings, "page-set", page_set); - - output_uri = gconf_client_get_string (gconf, OUTPUT_URI, NULL); - gtk_print_settings_set (settings, "output-uri", output_uri); - - output_file_format = gconf_client_get_string (gconf, OUTPUT_FILE_FORMAT, NULL); - gtk_print_settings_set (settings, "output-file-format",output_file_format); - - reverse = gconf_client_get_string (gconf, REVERSE, NULL); - gtk_print_settings_set (settings, "reverse", reverse); - - scale = gconf_client_get_string (gconf, SCALE, NULL); - gtk_print_settings_set (settings, "scale", scale); - - page_ranges = gconf_client_get_string (gconf, PAGE_RANGES, NULL); - gtk_print_settings_set (settings, "page-ranges", page_ranges); - - g_free (printer_name); - g_free (collate); - g_free (n_copies); - g_free (print_pages); - g_free (page_set); - g_free (scale); - g_free (output_uri); - g_free (output_file_format); - g_free (reverse); - g_free (page_ranges); - g_free (lpr_commandline); - g_object_unref (gconf); + list = gconf_client_get_list ( + client, PRINTING, GCONF_VALUE_STRING, &error); + if (error == NULL) { + g_slist_foreach (list, (GFunc) unpack_settings, settings); + g_slist_free (list); + } else { + g_warning ("%s: %s", G_STRFUNC, error->message); + g_error_free (error); + } + g_object_unref (client); return settings; } /* Saves the print settings */ void -e_print_save_config (GtkPrintSettings *settings) +e_print_save_settings (GtkPrintSettings *settings) { - GConfClient *gconf; - const gchar *printer_name; - const gchar *collate; - const gchar *n_copies; - const gchar *print_pages; - const gchar *page_set; - const gchar *scale; - const gchar *output_uri; - const gchar *output_file_format; - const gchar *reverse; - const gchar *page_ranges; - const gchar *lpr_commandline; - - gconf = gconf_client_get_default (); - printer_name = gtk_print_settings_get (settings, "printer"); - gconf_client_set_string (gconf, PRINTER, printer_name, NULL); - - scale = gtk_print_settings_get (settings, "scale"); - gconf_client_set_string (gconf, SCALE, scale, NULL); - - page_set = gtk_print_settings_get (settings, "page-set"); - gconf_client_set_string (gconf, PAGE_SET, page_set, NULL); - - print_pages = gtk_print_settings_get (settings, "print-pages"); - gconf_client_set_string (gconf, PRINT_PAGES, print_pages, NULL); - - lpr_commandline = gtk_print_settings_get (settings, "lpr-commandline"); - gconf_client_set_string (gconf, LPR_COMMANDLINE, lpr_commandline, NULL); + GConfClient *client; + GSList *list = NULL; + GError *error = NULL; - collate = gtk_print_settings_get (settings, "collate"); - gconf_client_set_string (gconf, COLLATE, collate, NULL); + client = gconf_client_get_default (); - output_uri = gtk_print_settings_get (settings, "output-uri"); - gconf_client_set_string (gconf, OUTPUT_URI, output_uri, NULL); - - output_file_format = gtk_print_settings_get (settings, "output-file-format"); - gconf_client_set_string (gconf, OUTPUT_FILE_FORMAT, output_file_format, NULL); - - reverse = gtk_print_settings_get (settings, "reverse"); - gconf_client_set_string (gconf, REVERSE, reverse, NULL); - - n_copies = gtk_print_settings_get (settings, "n_copies"); - gconf_client_set_string (gconf, N_COPIES, n_copies, NULL); - - page_ranges = gtk_print_settings_get (settings, "page-ranges"); - gconf_client_set_string (gconf, PAGE_RANGES, "page-ranges",NULL); - - g_object_unref (gconf); + gtk_print_settings_foreach ( + settings, (GtkPrintSettingsFunc) pack_settings, &list); + gconf_client_set_list ( + client, PRINTING, GCONF_VALUE_STRING, list, &error); + if (error != NULL) { + g_warning ("%s: %s", G_STRFUNC, error->message); + g_error_free (error); + } + g_slist_foreach (list, (GFunc) g_free, NULL); + g_slist_free (list); + + g_object_unref (client); } static void print_dialog_response(GtkWidget *widget, int resp, gpointer data) { if (resp == GTK_RESPONSE_OK) { - e_print_save_config (gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG (widget))); + e_print_save_settings (gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG (widget))); } } @@ -178,7 +112,8 @@ e_print_get_dialog (const char *title, int flags) GtkPrintSettings *settings; GtkWidget *dialog; - settings = e_print_load_config (); + settings = gtk_print_settings_new (); + settings = e_print_load_settings (); dialog = e_print_get_dialog_with_config (title, flags, settings); g_object_unref (settings); return dialog; -- cgit v1.2.3