From f17bfcef0db460229f3a5084e9f07300ccde28b7 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Mon, 4 Feb 2008 21:49:08 +0000 Subject: [PATCH] only connect to page layout changes for the lifetime of the dialog. 2008-02-04 Sven Neumann * plug-ins/print/print-page-layout.c: only connect to page layout changes for the lifetime of the dialog. * plug-ins/print/print-page-setup.[ch] * plug-ins/print/print.c: use a temporary procedure to notify the Print procedure about changes to the page setup. svn path=/trunk/; revision=24793 --- ChangeLog | 9 +++ plug-ins/print/print-page-layout.c | 6 +- plug-ins/print/print-page-setup.c | 16 +++--- plug-ins/print/print-page-setup.h | 5 +- plug-ins/print/print.c | 92 +++++++++++++++++++++++++++++- 5 files changed, 113 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 45954b8228..0e0eeea3ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-02-04 Sven Neumann + + * plug-ins/print/print-page-layout.c: only connect to page layout + changes for the lifetime of the dialog. + + * plug-ins/print/print-page-setup.[ch] + * plug-ins/print/print.c: use a temporary procedure to notify the + Print procedure about changes to the page setup. + 2008-02-04 Michael Natterer * app/base/gimphistogram.[ch]: add refcounting and replace free() diff --git a/plug-ins/print/print-page-layout.c b/plug-ins/print/print-page-layout.c index 0469722b90..819ff28dfc 100644 --- a/plug-ins/print/print-page-layout.c +++ b/plug-ins/print/print-page-layout.c @@ -198,9 +198,9 @@ print_page_layout_gui (PrintData *data) print_size_info_set_page_setup (&info); - g_signal_connect (data->operation, "notify::default-page-setup", - G_CALLBACK (print_page_setup_notify), - &info); + g_signal_connect_object (data->operation, "notify::default-page-setup", + G_CALLBACK (print_page_setup_notify), + layout, 0); return layout; } diff --git a/plug-ins/print/print-page-setup.c b/plug-ins/print/print-page-setup.c index 0966111bec..511acf8bf0 100644 --- a/plug-ins/print/print-page-setup.c +++ b/plug-ins/print/print-page-setup.c @@ -24,28 +24,26 @@ #include "print-page-setup.h" -static void print_page_setup_save (GtkPrintOperation *operation); - - void print_page_setup_dialog (GtkPrintOperation *operation) { - GtkPrintSettings *settings = gtk_print_settings_new (); + GtkPrintSettings *settings; GtkPageSetup *setup; - print_page_setup_load (operation); + g_return_if_fail (GTK_IS_PRINT_OPERATION (operation)); setup = gtk_print_operation_get_default_page_setup (operation); + settings = gtk_print_settings_new (); setup = gtk_print_run_page_setup_dialog (NULL, setup, settings); + g_object_unref (settings); gtk_print_operation_set_default_page_setup (operation, setup); - - print_page_setup_save (operation); } gboolean -print_page_setup_load (GtkPrintOperation *operation) +print_page_setup_load (GtkPrintOperation *operation, + gint32 image_ID) { GtkPageSetup *setup; gchar *filename; @@ -67,7 +65,7 @@ print_page_setup_load (GtkPrintOperation *operation) return FALSE; } -static void +void print_page_setup_save (GtkPrintOperation *operation) { GtkPageSetup *setup; diff --git a/plug-ins/print/print-page-setup.h b/plug-ins/print/print-page-setup.h index 0ecbd86cd1..ea9eb1e3ca 100644 --- a/plug-ins/print/print-page-setup.h +++ b/plug-ins/print/print-page-setup.h @@ -18,5 +18,8 @@ void print_page_setup_dialog (GtkPrintOperation *operation); -gboolean print_page_setup_load (GtkPrintOperation *operation); +gboolean print_page_setup_load (GtkPrintOperation *operation, + gint32 image_ID); +void print_page_setup_save (GtkPrintOperation *operation); + diff --git a/plug-ins/print/print.c b/plug-ins/print/print.c index 6a30832dbb..1e693a153a 100644 --- a/plug-ins/print/print.c +++ b/plug-ins/print/print.c @@ -68,6 +68,14 @@ static void draw_page (GtkPrintOperation *print, static GtkWidget * create_custom_widget (GtkPrintOperation *operation, PrintData *data); +static gchar * print_temp_proc_name (gint32 image_ID); +static gchar * print_temp_proc_install (gint32 image_ID); + + +/* Keep a reference to the current GtkPrintOperation + * for access by the temporary procedure. + */ +static GtkPrintOperation *print_operation = NULL; const GimpPlugInInfo PLUG_IN_INFO = @@ -178,6 +186,7 @@ print_image (gint32 image_ID, GError *error = NULL; gint32 orig_image_ID = image_ID; gint32 drawable_ID = gimp_image_get_active_drawable (image_ID); + gchar *temp_proc; PrintData data; GimpExportReturn export; @@ -193,7 +202,7 @@ print_image (gint32 image_ID, print_operation_set_name (operation, orig_image_ID); - print_page_setup_load (operation); + print_page_setup_load (operation, orig_image_ID); /* fill in the PrintData struct */ data.num_pages = 1; @@ -224,6 +233,10 @@ print_image (gint32 image_ID, G_CALLBACK (end_print), &image_ID); + print_operation = operation; + temp_proc = print_temp_proc_install (orig_image_ID); + gimp_extension_enable (); + if (interactive) { gimp_ui_init (PLUG_IN_BINARY, FALSE); @@ -249,6 +262,10 @@ print_image (gint32 image_ID, NULL, &error); } + gimp_uninstall_temp_proc (temp_proc); + g_free (temp_proc); + print_operation = NULL; + g_object_unref (operation); if (gimp_image_is_valid (image_ID)) @@ -267,14 +284,34 @@ static GimpPDBStatusType page_setup (gint32 image_ID) { GtkPrintOperation *operation; + gchar *name; gimp_ui_init (PLUG_IN_BINARY, FALSE); operation = gtk_print_operation_new (); + + print_page_setup_load (operation, image_ID); print_page_setup_dialog (operation); + print_page_setup_save (operation); + g_object_unref (operation); - /* FIXME: notify the print procedure about the changed page setup */ + /* now notify a running print procedure about this change */ + name = print_temp_proc_name (image_ID); + + if (name) + { + GimpParam *return_vals; + gint n_return_vals; + + return_vals = gimp_run_procedure (name, + &n_return_vals, + GIMP_PDB_IMAGE, image_ID, + GIMP_PDB_END); + gimp_destroy_params (return_vals, n_return_vals); + + g_free (name); + } return GIMP_PDB_SUCCESS; } @@ -362,3 +399,54 @@ create_custom_widget (GtkPrintOperation *operation, { return print_page_layout_gui (data); } + +static void +print_temp_proc_run (const gchar *name, + gint nparams, + const GimpParam *param, + gint *nreturn_vals, + GimpParam **return_vals) +{ + static GimpParam values[1]; + + values[0].type = GIMP_PDB_STATUS; + values[0].data.d_status = GIMP_PDB_SUCCESS; + + *nreturn_vals = 1; + *return_vals = values; + + if (print_operation && nparams == 1) + print_page_setup_load (print_operation, param[0].data.d_int32); +} + +static gchar * +print_temp_proc_name (gint32 image_ID) +{ + return g_strdup_printf (PRINT_PROC_NAME "-temp-%d", image_ID); +} + +static gchar * +print_temp_proc_install (gint32 image_ID) +{ + static const GimpParamDef args[] = + { + { GIMP_PDB_IMAGE, "image", "Image to print" } + }; + + gchar *name = print_temp_proc_name (image_ID); + + gimp_install_temp_proc (name, + "DON'T USE THIS ONE", + "Temporary procedure to notify the Print plug-in " + "about changes to the Page Setup.", + "Sven Neumann", + "Sven Neumann", + "2008", + NULL, + "", + GIMP_TEMPORARY, + G_N_ELEMENTS (args), 0, args, NULL, + print_temp_proc_run); + + return name; +}