From 419717c2d05cc4fffcbb5304c3df4cddbe96f824 Mon Sep 17 00:00:00 2001 From: Holger Berndt Date: Fri, 6 Feb 2009 13:04:54 +0000 Subject: [PATCH] 2009-02-06 [holger] 3.7.0cvs55 * src/prefs_common.c * src/prefs_common.h * src/printing.c Fix restoring of custom page setups for printing by temporarily caching the settings. This is a workaround for Gnome Bug #39018, and fixes Claws Mail Bug #1840. --- ChangeLog | 10 +++++++ PATCHSETS | 1 + configure.ac | 2 +- src/prefs_common.c | 8 +++++ src/prefs_common.h | 5 ++++ src/printing.c | 74 ++++++++++++++++++++++++++++++++++++++++++---- 6 files changed, 94 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index b5438ec99..e765053fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-02-06 [holger] 3.7.0cvs55 + + * src/prefs_common.c + * src/prefs_common.h + * src/printing.c + Fix restoring of custom page setups for printing by + temporarily caching the settings. + This is a workaround for Gnome Bug #39018, and fixes + Claws Mail Bug #1840. + 2009-02-06 [colin] 3.7.0cvs54 * src/mainwindow.c diff --git a/PATCHSETS b/PATCHSETS index 554ba8d05..fa27dea4d 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -3716,3 +3716,4 @@ ( cvs diff -u -r 1.274.2.296 -r 1.274.2.297 src/mainwindow.c; ) > 3.7.0cvs52.patchset ( cvs diff -u -r 1.382.2.497 -r 1.382.2.498 src/compose.c; ) > 3.7.0cvs53.patchset ( cvs diff -u -r 1.274.2.297 -r 1.274.2.298 src/mainwindow.c; ) > 3.7.0cvs54.patchset +( cvs diff -u -r 1.204.2.185 -r 1.204.2.186 src/prefs_common.c; cvs diff -u -r 1.103.2.121 -r 1.103.2.122 src/prefs_common.h; cvs diff -u -r 1.1.2.19 -r 1.1.2.20 src/printing.c; ) > 3.7.0cvs55.patchset diff --git a/configure.ac b/configure.ac index 9baa279d1..080748411 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=7 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=54 +EXTRA_VERSION=55 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/prefs_common.c b/src/prefs_common.c index 1333c9775..be9f07c3f 100644 --- a/src/prefs_common.c +++ b/src/prefs_common.c @@ -1096,6 +1096,14 @@ static PrefParam param[] = { NULL, NULL, NULL}, {"print_paper_orientation", "0", &prefs_common.print_paper_orientation, P_INT, NULL, NULL, NULL}, + {"print_margin_top", "-1", &prefs_common.print_margin_top, P_INT, + NULL, NULL, NULL}, + {"print_margin_bottom", "-1", &prefs_common.print_margin_bottom, P_INT, + NULL, NULL, NULL}, + {"print_margin_left", "-1", &prefs_common.print_margin_left, P_INT, + NULL, NULL, NULL}, + {"print_margin_right", "-1", &prefs_common.print_margin_right, P_INT, + NULL, NULL, NULL}, {"print_use_color", "0", &prefs_common.print_use_color, P_INT, NULL, NULL, NULL}, {"print_use_collate", "0", &prefs_common.print_use_collate, P_INT, diff --git a/src/prefs_common.h b/src/prefs_common.h index be9ca1b34..329250c6d 100644 --- a/src/prefs_common.h +++ b/src/prefs_common.h @@ -478,6 +478,11 @@ struct _PrefsCommon gchar *print_paper_type; gint print_paper_orientation; + gint print_margin_top; + gint print_margin_bottom; + gint print_margin_left; + gint print_margin_right; + gint print_use_color; gint print_use_collate; gint print_use_reverse; diff --git a/src/printing.c b/src/printing.c index 0d131c85e..d5c389ade 100644 --- a/src/printing.c +++ b/src/printing.c @@ -116,6 +116,8 @@ static void printing_layout_set_text_attributes(PrintData*, GtkPrintContext static gboolean printing_is_pango_gdk_color_equal(PangoColor*, GdkColor*); static gint printing_text_iter_get_offset_bytes(PrintData *, const GtkTextIter*); +#define PAGE_SETUP_STORAGE_FILE "print_page_setup" +#define PAGE_MARGIN_STORAGE_UNIT GTK_UNIT_MM #define PREVIEW_SCALE 72 #define PREVIEW_SHADOW_OFFSET 3 #define PREVIEW_ZOOM_FAC 1.41 @@ -175,13 +177,58 @@ void printing_store_settings(GtkPrintSettings *new_settings) GtkPageSetup *printing_get_page_setup(void) { if (page_setup == NULL) { + gboolean read_from_file; + char *page_setup_filename; + GKeyFile *keyfile; + gboolean key_file_read; + page_setup = gtk_page_setup_new(); - if (prefs_common.print_paper_type && *prefs_common.print_paper_type) { - GtkPaperSize *paper = gtk_paper_size_new(prefs_common.print_paper_type); - gtk_page_setup_set_paper_size(page_setup, paper); - gtk_paper_size_free(paper); + + read_from_file = FALSE; + +#if GTK_CHECK_VERSION(2,14,0) + /* try reading the page setup from file */ + page_setup_filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, PAGE_SETUP_STORAGE_FILE, NULL); + keyfile = g_key_file_new(); + key_file_read = g_key_file_load_from_file(keyfile, page_setup_filename, 0, NULL); + g_free(page_setup_filename); + + if(key_file_read) + read_from_file = gtk_page_setup_load_key_file(page_setup, keyfile, NULL, NULL); + g_key_file_free(keyfile); + + if(read_from_file) { + debug_print("Printing: Read page setup from key file\n"); + } + else { + debug_print("Printing: Could not read page setup from key file\n"); + } +#else + key_file_read = FALSE; + keyfile = NULL; + page_setup_filename = NULL; +#endif + + /* if reading from file did not work, or has not been tried (GTK+ < 2.14), use prefs */ + if(!read_from_file) { + /* paper size */ + if (prefs_common.print_paper_type && *prefs_common.print_paper_type) { + GtkPaperSize *paper = gtk_paper_size_new(prefs_common.print_paper_type); + gtk_page_setup_set_paper_size(page_setup, paper); + gtk_paper_size_free(paper); + } + /* orientation */ + gtk_page_setup_set_orientation(page_setup, prefs_common.print_paper_orientation); + /* margins */ + if(prefs_common.print_margin_top != -1) + gtk_page_setup_set_top_margin(page_setup, 0.01*prefs_common.print_margin_top, PAGE_MARGIN_STORAGE_UNIT); + if(prefs_common.print_margin_bottom != -1) + gtk_page_setup_set_bottom_margin(page_setup, 0.01*prefs_common.print_margin_bottom, PAGE_MARGIN_STORAGE_UNIT); + if(prefs_common.print_margin_left != -1) + gtk_page_setup_set_left_margin(page_setup, 0.01*prefs_common.print_margin_left, PAGE_MARGIN_STORAGE_UNIT); + if(prefs_common.print_margin_right != -1) + gtk_page_setup_set_right_margin(page_setup, 0.01*prefs_common.print_margin_right, PAGE_MARGIN_STORAGE_UNIT); } - gtk_page_setup_set_orientation(page_setup, prefs_common.print_paper_orientation); } return page_setup; } @@ -290,6 +337,9 @@ void printing_print(GtkTextView *text_view, GtkWindow *parent, gint sel_start, g void printing_page_setup(GtkWindow *parent) { GtkPageSetup *new_page_setup; + char *keyfile; + + keyfile = NULL; printing_get_settings(); printing_get_page_setup(); @@ -305,6 +355,20 @@ void printing_page_setup(GtkWindow *parent) prefs_common.print_paper_type = g_strdup(gtk_paper_size_get_name( gtk_page_setup_get_paper_size(page_setup))); prefs_common.print_paper_orientation = gtk_page_setup_get_orientation(page_setup); + /* store 100th millimeters */ + prefs_common.print_margin_top = (int) (100*gtk_page_setup_get_top_margin(page_setup, PAGE_MARGIN_STORAGE_UNIT)); + prefs_common.print_margin_bottom = (int) (100*gtk_page_setup_get_bottom_margin(page_setup, PAGE_MARGIN_STORAGE_UNIT)); + prefs_common.print_margin_left = (int) (100*gtk_page_setup_get_left_margin(page_setup, PAGE_MARGIN_STORAGE_UNIT)); + prefs_common.print_margin_right = (int) (100*gtk_page_setup_get_right_margin(page_setup, PAGE_MARGIN_STORAGE_UNIT)); + +#if GTK_CHECK_VERSION(2,14,0) + /* save to file */ + keyfile = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, PAGE_SETUP_STORAGE_FILE, NULL); + if(!gtk_page_setup_to_file(page_setup, keyfile, NULL)) { + debug_print("Printing: Could not store page setup in file `%s'\n", keyfile); + } + g_free(keyfile); +#endif } static gboolean cb_preview(GtkPrintOperation *operation, -- 2.25.1